Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I think that you and sammy have already found the answer. This is what the documentation says:

RETR_EXTERNAL retrieves only the extreme outer contours.

For hierarchy it states that:

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.

So in case of RETR_EXTERNAL you can use hierarchy[i][0] and hierarchy[i][1] for "neighbouring" contours at the top level but hierarchy[i][2] and hierarchy[i][3] will always be -1.

click to hide/show revision 2
No.2 Revision

I think that you and sammy have already found the answer. This is what the documentation says:

RETR_EXTERNAL retrieves only the extreme outer contours.

For hierarchy it states that:

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.

So in case of RETR_EXTERNAL you can use hierarchy[i][0] and hierarchy[i][1] for "neighbouring" contours at the top level but hierarchy[i][2] and hierarchy[i][3] will always be -1.


I would like to add this link for better understanding the flags of the function

click to hide/show revision 3
No.3 Revision

I think that you and sammy have already found the answer. This is what the documentation says:

RETR_EXTERNAL retrieves only the extreme outer contours.

For hierarchy it states that:

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.

So in case of RETR_EXTERNAL you can use hierarchy[i][0] and hierarchy[i][1] for "neighbouring" contours at the top level but hierarchy[i][2] and hierarchy[i][3] will always be -1.


I would like to add You can see this link for better understanding the flags of the function