0
votes

I am getting an assertion failed error in line 537 of Mat::at

OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si ze.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channel s()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3 ) - 1))*4) & 15) == elemSize1()) in unknown function, file c:\users\tim\document s\code\opencv\build\include\opencv2\core\mat.hpp, line 537

I am trying to populate matrices that I will use in the function cv::remap. The part of the code that is causing this failed assertion is below:

void Functions::PopulatedMapY(Mat image)
{
    mapy.create(image.rows, image.cols, CV_32FC1);
    for (int j = 0; j<image.rows; j++)
    {   
        float a = (image.rows - 1) - gazey;
        float b = (image.cols - 1) - gazex;
        for (int i = 0; i<image.cols; i++)
        {       
            mapy.at<float>(j,i) = map2y.at<float>(a+j,b+i);
        }   
    }
}

The matrix map2y was defined in the MapCreator Function as follows:

void Functions::MapCreator(Mat image, float const_a, float const_b)
{
    map2x.create(2*image.rows, 2*image.cols, CV_32FC1);
    map2y.create(2*image.rows, 2*image.cols, CV_32FC1);

    for (int m = 0; m<2*image.rows; m++)
    {
        ty = image.rows - m;
        for (int n = 0; n<2*image.cols; n++)
        {
            tx = image.cols - n;
            map2x.at<float>(m,n) = n;
            map2y.at<float>(m,n) = m +const_b*exp(-pow(tx,2)/pow(const_a, 2))*Signum(ty);

    }
    }

}

Any help would be much appreciated!

1
Hi, can you provide more info, like the values of i and j when it crashes and the values of gazey and gazex. - Andrei Toader
Hi, gazey and gazex can vary between 0 and image.rows - 1 and image.cols - 1 respectively. The program compiles and crashes as soon as it runs. Is there a way I can find out the value of I and j when it crashes? Thanks! - user4095744
btw a and b should be ints...you should try to access indices not floats. a + i should be an int. - Andrei Toader
So did you manage to do it or not? - Andrei Toader

1 Answers

0
votes

From your error code you can find that the assertion goes false after the Mat::at call and inside this method your code goes false if:
a. The nr. of channels is less than 2.
b. data is null
c. (unsigned)i0 < (unsigned)size.p[0]
plus some others.
My suggestion in your case is the nr. of channels. CV_32FC1 means like that:
CV_< bit_depth > (S|U|F)C< nr_channels >. I suppose here is the problem, the template parameter or the data is null.
My solution just use CV_32F instead.
As a big reference take a look here:
OpenCV Error: Assertion failed, mat.cpp line 537