1

I've this image:

EDIT Sorry but I had to remove the images!

I need to extract the contour of the non-black picture, so I used findcontour with the CV_RETR_EXTERNAL parameter, but I obtain this:

Here's the code:

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

        }

how can I resolve?

4

1 回答 1

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);
于 2015-04-01T22:26:25.710 回答