Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Opencv findcontours CV_RETR_外部不工作_C++_Opencv_Canny Operator_Opencv Contour - Fatal编程技术网

C++ Opencv findcontours CV_RETR_外部不工作

C++ Opencv findcontours CV_RETR_外部不工作,c++,opencv,canny-operator,opencv-contour,C++,Opencv,Canny Operator,Opencv Contour,我有这样一张照片: 编辑 很抱歉,我必须删除这些图片 我需要提取非黑色图片的轮廓,因此我使用了带有CV_RETR_外部参数的findcontour,但我得到了以下结果: 代码如下: static Mat canny_output, grey,draw; vector<vector<Point>> contours; cvtColor(final_img, grey, CV_BGR2GRAY); Canny(grey, can

我有这样一张照片:

编辑 很抱歉,我必须删除这些图片

我需要提取非黑色图片的轮廓,因此我使用了带有CV_RETR_外部参数的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));

        }
静态Mat canny_输出,灰色,绘图;
矢量等值线;
CVT颜色(最终颜色、灰色、CV颜色);
Canny(灰色,Canny_输出,100200);
findContours(canny_输出、轮廓、CV_RETR_外部、CV_链_近似_简单);
draw=Mat::zeros(canny_output.size(),CV_8UC3);
对于(size_t i=0;i

如何解析?

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