예제 #1
0
    /// <summary>
    /// Fit ellipse through contour points in a least square sense.
    /// </summary>
    /// <param name="c">Contour</param>
    /// <returns>Ellipse</returns>
    private Emgu.CV.Structure.Ellipse FitByContour(Emgu.CV.Contour<System.Drawing.Point> c) {
      System.Drawing.PointF[] mypoints = Array.ConvertAll(
        c.ToArray<System.Drawing.Point>(),
        value => new System.Drawing.PointF(value.X, value.Y)
      );

      Emgu.CV.Structure.Ellipse e = Emgu.CV.PointCollection.EllipseLeastSquareFitting(mypoints);
      Emgu.CV.Structure.MCvBox2D box = e.MCvBox2D;
      // Modify ellipse to have width = a, height = b in the ellipse equation.
      box.size.Height *= 0.5f;
      box.size.Width *= 0.5f;
      return new Emgu.CV.Structure.Ellipse(box);
    }