Ask Your Question

Revision history [back]

No segmentation fault while it should

Sometimes I do not get a segmentation fault (while I should) when I access the image with:

image.at<uchar>()

For example, if I declare an image of size 800 x 800 and access a pixel outside this range I may not get a segmentation fault. E.g.

Mat image_test(800, 800, CV_8UC1, Scalar(0));
std::cout << "value: " << (int) image_test.at<uchar>(850, 2) << std::endl;

In the code above it just prints a value 146 which is of course impossible since all pixels are initialized with zero. My question is what does really happen behind the scene?