Ask Your Question

bkarpati's profile - activity

2019-11-29 06:53:18 -0600 asked a question Setting codec parameters with FFMPEG backend

Setting codec parameters with FFMPEG backend I am using OpenCV's VideoWriter to record videos with FFMPEG. I am using th

2015-08-14 05:43:25 -0600 commented answer Creating a sub array of a Mat throws assertion error

You see, my problem is, that if you have the following code for example:

    for (int r = 0; r < image.rows; ++r) {
    for (int c = 0; c < image.cols; ++c) {
        image.at<type>(r,c) = something here;
    }
}

Then you are accessing pixels using (row, column) not (column, row).

UPDATE:

I have just done some simple drawings, which resulted in exactly what you said, the origin is at the top left corner, and coordinates can be accessed using (column, row).

Considering this, you see, why it is confusing, in my code, you can access pixels using (row, column)

2015-08-13 13:23:32 -0600 commented answer Creating a sub array of a Mat throws assertion error

What I don't understand is, that OpenCV has the (0,0) coordinate at the upper left corner, the first coordinate is for the row, the second is for the column, and the Rect function asks for an x coordinate first, then a y, so it should ask for the row first. Yet, it works only, when I provide the column first. Or am I missing out on something?

2015-08-13 10:56:12 -0600 commented answer Creating a sub array of a Mat throws assertion error

You are right, now I just don't understand why they would mark the y coordinate with x and vice versa...

2015-08-13 10:39:12 -0600 commented answer Creating a sub array of a Mat throws assertion error

Thank you, but unfortunately this does not solve my problem.

2015-08-13 10:03:47 -0600 asked a question Creating a sub array of a Mat throws assertion error

Hey there,

In my program, I am looping through a 2D Mat, using a rectangle with width 5 and height 1, and checking float point values in this sub array. My code goes as follow:

for (int i = 0; i < dist.rows; ++i) {  
    for (int j = 2; j < dist.cols -2; ++j) {
        search_mask = dist(Rect(i, j - 2, 5, 1).clone();
        minMaxLoc(search_mask, NULL, NULL, NULL, &local_max);
        if (local_max.x == i) {
            skeleton.at<uchar>(i, j) = 255;
        }
    }
}

My original picture has size 640*363. When the first loop reached the value i = 359, I get an assertion error:

OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv:: Mat::Mat

As far as I can tell, the problem is, that when i = 359, roi.x = 359, roi. width = 5 and so roi.x + roi.width = 364, and m.cols = 363 and so 364 <= 363 is false.

My first question is, am I doing something wrong here?

My second question, why the hell would the number of rows matter when it comes to deciding if the number of columns in the sub array is not greater, than the number of columns in the original image.

Thank you for your help.

Also, sorry if I have left something important out.