【问题标题】:Opencv findcontours CV_RETR_EXTERNAL not workingOpencv findcontours CV_RETR_EXTERNAL 不工作
【发布时间】:2015-06-06 09:27:20
【问题描述】:

我有这张图片:

编辑 抱歉,我不得不删除图片!

我需要提取非黑色图片的轮廓,所以我使用了带有CV_RETR_EXTERNAL参数的findcontour,但是我得到了这个:

代码如下:

static Mat canny_output, grey,draw;
        vector<vector<Point>> contours;
        cvtColor(final_img, grey, CV_BGR2GRAY);
        Canny(grey, canny_output, 100, 200);
        findContours(canny_output, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

        draw = Mat::zeros(canny_output.size(), CV_8UC3);


        for (size_t i = 0; i < contours.size(); i++)
        {
            drawContours(draw, contours, i, Scalar(255, 0, 0));

        }

我该如何解决?

【问题讨论】:

    标签: c++ opencv canny-operator opencv-contour


    【解决方案1】:

    只需添加一个具有最小阈值的二值化,然后移除 Canny:

    cvtColor(final_img, grey, CV_BGR2GRAY);
    //Threshold=1: very low value, anyway the rest of the image is pure black
    threshold(grey, binary, 1, 255, CV_THRESH_BINARY);
    findContours(binary, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-12
      • 2012-12-14
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 2016-04-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多