0
votes

I am converting Python OpenCV code to Emgu. In Python, function findContours can return hierarchy

hierarchy – Optional output vector, containing information about the image topology. It has as many elements as the number of contours. For each i-th contour contours[i] , the elements hierarchy[i][0] , hiearchy[i][1] , hiearchy[i][2] , and hiearchy[i][3] are set to 0-based indices in contours of the next and previous contours at the same hierarchical level, the first child contour and the parent contour, respectively. If for the contour i there are no next, previous, parent, or nested contours, the corresponding elements of hierarchy[i] will be negative.

Unfortunately in Emgu I can't not return such array for findContours function.Is there any equivalent for this?

1

1 Answers

6
votes

If you choose CV_RETR_TREE as retrieval type, the Contour<Point> that is returned will contain a hierarchical tree structure.

This image from here shows how you can navigate in the hierarchy using h_next and v_next pointers in OpenCV (i.e. HNext and VNext in Emgu CV).

Tree structure

In this way, you can get the whole hierarchy.