I would like to crop a cv::Mat. Refer to How to crop a CvMat in OpenCV? , I wrote the following piece of code.
// I would like to crop around this central point.
x = 100;
y = 100;
int centerOff = 30, size = 61;
cv::Mat img2 = sourceImage(Rect((int)x-centerOff, (int)y-centerOff, size, size));
for (int i=0; i<size; i++) {
for (int j=0; j<size; j++) {
std::cout << (int)img2.at<uchar>(i, j) << " " << (int)sourceImage.at<uchar>(x-centerOff+i, y-centerOff+j) << "\n";
}
}
It turns out the output of img2 and sourceImage is different. I would like to know the reason of it.