Ellipse Fitting in CSharp

From Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
Revision as of 03:30, 24 November 2010 by Inuxejiq (talk | contribs)
Jump to navigation Jump to search

This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page


System Requirement

Component Requirement Detail
Emgu CV Version Available only from SVN
Operation System Cross Platform

Source Code

<source lang="csharp">

  1. region generate random points

System.Random r = new Random(); int sampleCount = 100; Ellipse modelEllipse = new Ellipse(new PointF(200, 200), new SizeF(150, 60), 30); PointF[] pts = PointCollection.GeneratePointCloud(modelEllipse, sampleCount);

  1. endregion

Stopwatch watch = Stopwatch.StartNew(); Ellipse fittedEllipse = PointCollection.EllipseLeastSquareFitting(pts); watch.Stop();

  1. region draw the points and the fitted ellipse

Image<Bgr, byte> img = new Image<Bgr, byte>(400, 400, new Bgr(Color.White)); foreach (PointF p in pts)

  img.Draw(new CircleF(p, 2), new Bgr(Color.Green), 1);

img.Draw(fittedEllipse, new Bgr(Color.Red), 2);

  1. endregion

ImageViewer.Show(img, String.Format("Time used: {0}milliseconds", watch.ElapsedMilliseconds));