Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

FindContours Duplicate Points

I am using OpenCV 3.4.1 with VS2015 C++ on a Win10 platform.

My question relates to findContours and whether that should be returning duplicate points within a contour.

For example, I have a test image like this:

image description

I do Canny on it and then I run findContours like this:


When I check the resulting contours like this:

for (int x = 0; x < Images->Contours.size(); x++)
    for (int y = 0; y < Images->Contours[x].size(); y++)
        for (int z = y + 1; z < Images->Contours[x].size(); z++)
            if (Images->Contours[x][y] == Images->Contours[x][z])
                printf("Contours duplicate point: x: %d, y: %d z: %d\n", x, y, z);

I can see there there are many/hundreds of duplicate points within a given contour.

image description

The presence of the duplicates seems to cause a problem with the drawContours function.
Nevertheless, this image shows that 6 contours were detected with ~19,000 points comprising all the contours, the largest contour has ~18,000 points, but there are 478 points that are duplicated within a contour.

However, this only seems to occur if the total number of points in a given contour is fairly large, e.g., > 2000 points. If I arrange the image so that no contour has more than ~2000 points, as below, then there are no duplicates.

image description

In this image, there are 11 contours, there are ~10,000 points comprising all the contours, with the largest contour having ~1,600 points, and no duplicates.

Before I try and get deep into findContours or something else, I thought I would ask: anyone have any ideas why I am seeing duplicate points within a contour?

Thanks for any help.