简体   繁体   English

OpenCV中的ROI图片错误

[英]Error ROI image in OpenCV

I have a binary image with some noise. 我的二进制图像有些杂音。 I want to reduce the noise by using a rectangle size(10x10) sliding along the image. 我想通过使用沿图像滑动的矩形大小(10x10)来减少噪声。

If the rectangle consists of more than 20 nonZero pixels, I will copy ROI to the destination image. 如果矩形包含20个以上的nonZero像素,我将ROI复制到目标图像。

for (int i = 0; i < binary.rows-10; i+=10){
    for (int j = 0; j < binary.cols-10; j+=10)
    {
        cv::Rect Roi(i, j, 10, 10);
        cv::Mat countImg = cv::Mat(10, 10, CV_8UC1);
        countImg = cv::Mat(binary, Roi);

        if (cv::countNonZero(countImg)>20)
        {
            countImg.copyTo(binary_filter.rowRange(i, i + 10).colRange(j, j + 10));
        }
    }
}

The program encountered an error at function countImg = cv::Mat(binary, Roi); 程序在函数countImg = cv::Mat(binary, Roi);处遇到错误countImg = cv::Mat(binary, Roi); Who can explain? 谁能解释?

The real problem happens here: 真正的问题发生在这里:

cv::Rect Roi(i, j, 10, 10);

cv::Rect is of format (x, y, width, height) not cv::Rect的格式(x, y, width, height)不是 (y, x, width_, height) .


To make it work, change it to 要使其正常运行,请将其更改为

cv::Rect Roi(j, i, 10, 10);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM