Minimum Area Rectangle in CSharp: Difference between revisions

From EMGU
Jump to navigation Jump to search
Line 23: Line 23:
#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<Bgr, byte> img = new Image<Bgr, byte>(400, 400, new Bgr(Color.White));
img.Draw(box, new Bgr(Color.Red), 1);
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);
img.Draw(box, new Bgr(Color.Red), 2);
#endregion
#endregion


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


== Result ==
== Result ==
[[image:MinimumAreaRectangleExample.png]]
[[image:MinimumAreaRectangleExample.png]]

Revision as of 19:24, 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(90, 60), -60);
PointF[] pts = PointCollection.GeneratePointCloud(modelEllipse, sampleCount);
#endregion

Stopwatch watch = Stopwatch.StartNew();
MCvBox2D box = PointCollection.MinAreaRect(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));
img.Draw(box, new Bgr(Color.Red), 1);
foreach (PointF p in pts)
   img.Draw(new CircleF(p, 2), new Bgr(Color.Green), 1);
#endregion

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

Result