Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How would I sort contours from RETR_TREE into a tree/pyrimid based on hierarchy?

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!

How would I sort contours from cvFindContours using RETR_TREE into a tree/pyrimid based on hierarchy?

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!