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…')
 
Line 1: Line 1:
 +
----
 +
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 +
----
 +
=[http://ovarynetyv.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
 +
----
 +
=[http://ovarynetyv.co.cc CLICK HERE]=
 +
----
 +
</div>
 
== System Requirement ==
 
== System Requirement ==
 
{| style="text-align:center" border="1px" cellpadding="10" cellspacing="0"
 
{| style="text-align:center" border="1px" cellpadding="10" cellspacing="0"
Line 9: Line 17:
  
 
== Source Code ==
 
== Source Code ==
<source lang="csharp">
+
&lt;source lang="csharp">
 
#region generate random points
 
#region generate random points
 
System.Random r = new Random();
 
System.Random r = new Random();
Line 22: Line 30:
  
 
#region draw the points and the fitted ellipse
 
#region draw the points and the fitted ellipse
Image<Bgr, byte> img = new Image<Bgr, byte>(400, 400, new Bgr(Color.White));
+
Image&lt;Bgr, byte> img = new Image&lt;Bgr, byte>(400, 400, new Bgr(Color.White));
 
foreach (PointF p in pts)
 
foreach (PointF p in pts)
 
   img.Draw(new CircleF(p, 2), new Bgr(Color.Green), 1);
 
   img.Draw(new CircleF(p, 2), new Bgr(Color.Green), 1);
Line 30: Line 38:
 
ImageViewer.Show(img, String.Format("Time used: {0}milliseconds", watch.ElapsedMilliseconds));
 
ImageViewer.Show(img, String.Format("Time used: {0}milliseconds", watch.ElapsedMilliseconds));
  
</source>
+
&lt;/source>
  
 
== Result ==
 
== Result ==
 
[[image:EllipsefittingExample.png]]
 
[[image:EllipsefittingExample.png]]

Revision as of 03:30, 24 November 2010



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


CLICK HERE


System Requirement

Component Requirement Detail
Emgu CV Version 2.0.1.0 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));

</source>

Result

EllipsefittingExample.png