Browse through the hierarchy of paths found by the FindContours?

This should be easy for C ++ developers using OpenCV directly. However, what I'm using is Emgu (the OpenCV shell for .NET), and in the latest version we have a method CvInvoke.FindContoursthat returns void, the output is passed by the parameter reference and is of type VectorOfVectorOfPoint.

Here is a simple call:

//outputResult is a VectorOfVectorOfPoint
CvInvoke.FindContours(inputImage, outputResult, null, RetrType.Tree, 
                      ChainApproxMethod.ChainApproxSimple);

In mode, RetrType.Listwe can simply convert the result to some array of arrays and easily skip all contours. However, here I would like to move along all the contours in the tree. I think that we should do something with our own (insecure) C ++ code here with a pointer (access via the property of the Ptroutput result). But I am wondering if there is a solution more convenient for .NET for this. And even if using a pointer is the only solution, I still don't know how to delve into it Ptrto move around the path tree.

The code examples followed by the Emgu installation have a snippet using CvInvoke.FindContourTreeinstead (and which returns a int[,]).

+4
1

, Mat :

Mat hierarchy = new Mat() ;
CvInvoke.FindContours(inputImage, outputResult, hierarchy, RetrType.Tree, 
                  ChainApproxMethod.ChainApproxSimple);

hierarchy (. Python OpenCV):

hierarchy Mat 1 x outputResult x 4. , i:

  • hierachy[0,i,0] - ( ) - 1,
  • hierachy[0,i,1] - - 1,
  • hierachy[0,i,2] - i - 1,
  • hierachy[0,i,3] - i - 1,

, .

outputResult, .

+6

All Articles