Ask Your Question

Revision history [back]

Indexing beyond size of Mat still gives a result

I have loaded a jpg image that is 480 columns by 640 rows into a Mat and I want to return the pixel value at a certain position. I load a colour image and then I convert it to greyscale. Obviously I want to return pixel values between columns 0 to 479 and rows 0 to 639 but if I use an index of say (500,500) then I still get an answer without any crash or error. In fact an index up to (0,622575) works or even (1,622095), basically 622575 minus the length of 1 row (480). How is is it possible to index beyond the size of the Mat ? I am running this in Xcode 5.5.1 (debug mode) and I am using OpenCV 2.4.9 installed via MacPorts.

Mat colourImage = imread("/Path_to/a.jpg");

Mat greyImage;

int rowpos = 500;

int colpos = 500;

cvtColor(colourImage,greyImage,CV_BGR2GRAY);

uchar gg = greyImage.at< uchar>(rowpos,colpos);

cout << "pixel value " << (int)gg << endl;