Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have a look at the shape detection example in the EMGU.Examples folder. It shows you how to deal with contours. I have copied the relevant code below for your reference but it's much better to have a look at the example.</p> <pre><code> #region Find triangles and rectangles List&lt;Triangle2DF&gt; triangleList = new List&lt;Triangle2DF&gt;(); List&lt;MCvBox2D&gt; boxList = new List&lt;MCvBox2D&gt;(); //a box is a rotated rectangle using (MemStorage storage = new MemStorage()) //allocate storage for contour approximation for (Contour&lt;Point&gt; contours = cannyEdges.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage); contours != null; contours = contours.HNext) { Contour&lt;Point&gt; currentContour = contours.ApproxPoly(contours.Perimeter * 0.05, storage); if (currentContour.Area &gt; 250) //only consider contours with area greater than 250 { if (currentContour.Total == 3) //The contour has 3 vertices, it is a triangle { Point[] pts = currentContour.ToArray(); triangleList.Add(new Triangle2DF( pts[0], pts[1], pts[2] )); } else if (currentContour.Total == 4) //The contour has 4 vertices. { #region determine if all the angles in the contour are within [80, 100] degree bool isRectangle = true; Point[] pts = currentContour.ToArray(); LineSegment2D[] edges = PointCollection.PolyLine(pts, true); for (int i = 0; i &lt; edges.Length; i++) { double angle = Math.Abs( edges[(i + 1) % edges.Length].GetExteriorAngleDegree(edges[i])); if (angle &lt; 80 || angle &gt; 100) { isRectangle = false; break; } } #endregion if (isRectangle) boxList.Add(currentContour.GetMinAreaRect()); } } } #endregion </code></pre> <p>Let me know if you need any additional help and if any errors pop up,</p> <p>Cheers,</p> <p>Chris</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload