找到轮廓而发现显然只有3个轮廓的这么多轮廓是否正常?

原始图像和绘制后找到的轮廓如下所示:


代码是:

Mat image;
    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;
    image = imread(argv[1], 0);   // Read the file
    findContours(image, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
    cout << contours.size();


    RNG rng(12345);
    Mat drawing = Mat::zeros(image.size(), CV_8UC3);
    for (int i = 0; i< contours.size(); i++)
    {
        Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
        drawContours(drawing, contours, i, color, 2, 8, hierarchy, 0, Point());
    }
    /// Show in a window
    namedWindow("Contours", CV_WINDOW_AUTOSIZE);
    imshow("Contours", drawing);
namedWindow("Display window", WINDOW_AUTOSIZE);// Create a window for display.
    imshow("Display window", image);                   // Show our image inside it.

最佳答案

我认为您正在读取Jpeg或实际输入图像的任何其他压缩版本,这会增加这些噪音。查找轮廓需要二进制图像。如果要处理此图像,只需在找到轮廓之前应用阈值!请注意,您的源图像对我来说很好用!

关于opencv - findcontours发现太多轮廓,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28253559/

10-11 17:02