【问题标题】:Morphology Fill Halo in Binary Matrix二进制矩阵中的形态填充光环
【发布时间】:2016-06-16 19:30:11
【问题描述】:

有什么方法可以使用 OpenCV 将光环的中心孔设置为白色像素,这样我就可以得到一个纯白色的圆圈?我尝试过使用扩张和侵蚀形态函数。它们使图像更清晰(如您所见),但中心仍然是黑色。

【问题讨论】:

    标签: opencv image-processing


    【解决方案1】:

    你可以简单的找到外轮廓,然后填充整个轮廓:

    代码:

    #include <opencv2\opencv.hpp>
    #include <vector>
    using namespace std;
    using namespace cv;
    
    int main()
    {
        // Read grayscale image
        Mat1b img = imread("path_to_image", IMREAD_GRAYSCALE);
    
        // Find external contour
        vector<vector<Point>> contours;
        findContours(img.clone(), contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
    
        // Check that you find something
        if (!contours.empty())
        {
            // Fill the first (and only) contour with white
            drawContours(img, contours, 0, Scalar(255), CV_FILLED);
        }
    
        // Show result
        imshow("Filled", img);
        waitKey();
    
        return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-09-26
      • 1970-01-01
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      • 2021-07-11
      • 2013-01-19
      • 1970-01-01
      • 2017-03-06
      相关资源
      最近更新 更多