从cv :: Mat中裁剪一个矩形

时间:2017-03-27 04:38:07

标签: c++ image opencv opencv-mat

我想裁剪一个cv :: Mat。请参阅How to crop a CvMat in OpenCV?,我写了以下代码。

        // 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"; 
            }
        }

事实证明img2和sourceImage的输出是不同的。我想知道它的原因。

0 个答案:

没有答案