Difference between revisions of "Minimum Enclosing Circle in CSharp"
Jump to navigation
Jump to search
m (Undo revision 1270 by Sanders Dowdy (talk)) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== 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 17: | Line 9: | ||
== Source Code == | == Source Code == | ||
− | + | <source lang="csharp"> | |
#region generate random points | #region generate random points | ||
System.Random r = new Random(); | System.Random r = new Random(); | ||
Line 30: | Line 22: | ||
#region draw the points and the circle | #region draw the points and the circle | ||
− | Image | + | Image<Bgr, byte> img = new Image<Bgr, byte>(400, 400, new Bgr(Color.White)); |
img.Draw(circle, new Bgr(Color.Red), 1); | img.Draw(circle, new Bgr(Color.Red), 1); | ||
foreach (PointF p in pts) | foreach (PointF p in pts) | ||
Line 37: | Line 29: | ||
ImageViewer.Show(img, String.Format("Time used: {0} milliseconds", watch.ElapsedMilliseconds)); | ImageViewer.Show(img, String.Format("Time used: {0} milliseconds", watch.ElapsedMilliseconds)); | ||
− | + | </source> | |
== Result == | == Result == | ||
[[image:MinimumEnclosingCircleExample.png]] | [[image:MinimumEnclosingCircleExample.png]] |
Latest revision as of 13:51, 14 February 2012
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();
CircleF circle = PointCollection.MinEnclosingCircle(pts);
watch.Stop();
#region draw the points and the circle
Image<Bgr, byte> img = new Image<Bgr, byte>(400, 400, new Bgr(Color.White));
img.Draw(circle, 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));