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!
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.