我有这张图片:

编辑
抱歉,但是我必须删除图像!

我需要提取非黑色图片的轮廓,因此我将findcontour与CV_RETR_EXTERNAL参数一起使用,但是我得到了以下信息:

这是代码:

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));

        }

我该如何解决?

最佳答案

只需添加最小阈值的二值化,然后删除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);

关于c++ - OpenCV的findcontours CV_RETR_EXTERNAL不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29395771/

10-10 16:12