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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With