简体   繁体   中英

OpenCV Error: Assertion

Mat m1 = Mat(500, 300, CV_64F, Vec3b(255,255,255));
  for (int i = 0; i < m1.rows; ++i)
    for (int j = 0; j < m1.cols; ++j)
    {
        Vec3b color=m1.at<Vec3b>(Point(i, j));
    }
imshow("test2", m1);
waitKey();

The variable color should contain the color of the pixel which is white but i when i run the code i get the error:

OpenCV Error: Assertion failed (((((sizeof(size_t)<<28)|0x8442211) >> ((traits::Depth<_Tp>::value) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file c:\\opencv\\build\\include\\opencv2\\core\\mat.inl.hpp, line 1118

The error message is telling you what you need to know. You've gone out of bounds!

Try:

Point(j, i)

Columns correspond to x . Rows correspond to y .

try this

Mat m1 = Mat(500, 300, CV_64F, Vec3b(255,255,255));
  for (int i = 0; i < m1.rows; ++i)
    for (int j = 0; j < m1.cols; ++j)
    {
        Vec3b color=m1.at<Vec3b>(i, j);//changed
    }
imshow("test2", m1);
waitKey();

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM