Difference between revisions of "Ellipse Fitting in CSharp"

From Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
Jump to: navigation, search
(Created page with '== System Requirement == {| style="text-align:center" border="1px" cellpadding="10" cellspacing="0" !Component || Requirement || Detail |- |Emgu CV || Version 2.0.1.0 || Availab…')
(No difference)

Revision as of 19:13, 20 August 2009

System Requirement

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

Source Code

#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);
#endregion

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

#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);
#endregion

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

Result

EllipsefittingExample.png