Display hierarchy lvl on contour.

asked 2020-11-03 09:30:49 -0600

Hello,

I'm learning the hierarchy on python. I'd like to see the hierarchy lvl for each contour like on this site : https://docs.opencv.org/master/d9/d8b... I have this picture : image description Then i find contours then their hierarchy :

hierarchy [[[ 1 -1 -1 -1] [ 2 0 -1 -1] [ 3 1 -1 -1] [ 4 2 -1 -1] [ 5 3 -1 -1] [-1 4 -1 -1]]]

I suppose since i have 6 shapes, I have 6 contours (0 to 5). To understand this array i'd like the display these numbers on my picture.

Have you an idea to do this ?

Thanks.

edit retag flag offensive close merge delete

Comments

see this code i think you can change it according to your needs

sturkmen gravatar imagesturkmen ( 2020-11-03 10:12:39 -0600 )edit

you image is a bad example, it has no hierarchy at all (there is nothing "nested") so the parent and child entries are all -1

berak gravatar imageberak ( 2020-11-03 10:28:50 -0600 )edit