Mat::at throws error: Assertion failed ((unsigned)i0 < (unsigned)size.p[0]) in opencv\build\include\opencv2\core\mat.inl.hpp, line 1100
Hello guys! I am new to OpenCV and I have tried to write a program that takes as input the images my camera captures live and modify some pixels. Right now I was trying to invert the values of a grayscale image when this error appeared. I think I got sth wrong because I have used a line of code before and it worked just fine. Can you please help me out?
Here is the code:
while(1){
VideoCapture cap(0);
if (!cap.isOpened())
return 1;
Mat src,dst,gray;
cap.read(src);
cvtColor(src, gray, COLOR_BGR2GRAY);
dst = gray;
for (int y = 0; y < dst.cols; y++) {
for (int x = 0; x < dst.rows; x++) {
dst.at<uchar>(y, x) = 255 - dst.at<uchar>(y, x);
}
}
if (waitKey(30) == 's')
break;
}
I have used the line: "dst.at<uchar>(y, x) = 255 - dst.at<uchar>(y, x);" before and it worked just fine. What could be wrong?
Error: Assertion failed ((unsigned)i0 < (unsigned)size.p[0]) in cv::Mat::at, file ..\opencv\build\include\opencv2\core\mat.inl.hpp, line 1100
dst.at<uchar>(row,col)
and why do you open VideoCapture in while loop?
Don't loop over pixels
becomes dst =255-dst