I am having a some trouble with findContours in opencv. There is too much data in the output and I know that properly using the hierarchy is the key. Given the image below from the opencv docs:

Opencv Docs

I would like to draw all the contours except for 2a and 3a. What is the proper way to traverse the hierarchy and findContour arguments to achieve that result?

有帮助吗?

解决方案

Contours found by findContours function has direction. Objects are counter clockwise, and holes are clockwise. So if you check signed area of each contour, you will know whether this is a hole or not by its sign. Signed area of contour can be calculated in following way:

contourArea(contour, true);

Of course using hierarchy is a good approach as well but I think this approach is simpler to understand and implement.

其他提示

Adding to what @Michael Burdinov said, returns +ve and -ve values for objects or holdes

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top