For example if I were to input the hierarchy from 4.RETR_TREE here
hierarchy =
array([[[ 7, -1, 1, -1],
[-1, -1, 2, 0],
[-1, -1, 3, 1],
[-1, -1, 4, 2],
[-1, -1, 5, 3],
[ 6, -1, -1, 4],
[-1, 5, -1, 4],
[ 8, 0, -1, -1],
[-1, 7, -1, -1]]])
I would like to get this output:
{0:{1:{2:{3:{4:{5:{},6:{}}}}}},
7:{},
8:{}}
I am looking to do this to build a tree model in Qt so I can easily see which contours contain which others. If you have a better idea of how to turn the hierarchy data into a Qt tree model that would also be appreciated.
Thanks in advance!