title: C# - Emgu CV - FindContours hierarchy data always null
body: <p>I am working on contour finding in a C# EmguCV project. For this project it is essential that I obtain the contour hierarchy data. I have used this method before in a C++ OpenCV project, so I understand the workings of the <code>FindContours</code> method and the <code>Hierarchy</code> information. Please find the relevant code below:</p>
  
  <pre><code>Mat grayImage = new Mat(originalImage.Size, originalImage.Depth, 1);
  Mat edges = new Mat(originalImage.Size, originalImage.Depth, 1);
  
  CvInvoke.CvtColor(originalImage, grayImage, ColorConversion.Bgr2Gray);            
  CvInvoke.Canny(grayImage, edges, 100, 200, 3);
  
  var contours = new VectorOfVectorOfPoint();
  
  Mat hierarchy = new Mat();
  CvInvoke.FindContours(edges, contours, hierarchy, RetrType.Tree, ChainApproxMethod.ChainApproxSimple);
  </code></pre>
  
  <p>When I run this code contours are found as expected. Also the <code>Hierarchy Mat</code> object seems to get populated as expected, namely <code>1 x size of outputResult x 4</code> (see image below), yet the data in this object remains <code>null</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/gE8Lj.png" rel="nofollow noreferrer">Screenshot of hierarchy mat object</a></p>
  
  <p>I have not been able to find an answer on how to extract the hierarchy contour (tree) data from this object. I have seen in <a href="https://stackoverflow.com/a/37470968/7397065">other StackOverflow posts (see also the comments)</a> that others have been struggling and/or that there may be bugs in the EmguCV 3.x library, but I have not been able to find an answer.</p>
  
  <p>My question is thus: is it normal that the data field in the <code>Hierarchy Mat</code> object is <code>null</code>?</p>
  
  <ul>
  <li>If so: how do I extract the relevant hierarchical data from this <code>Mat</code> object?</li>
  <li>If not: is there a way to circumvent this bug where the hierarchical data is <code>null</code>? Would it for example be possible to downgrade to EmguCV 2.x?</li>
  </ul>