Minimum Enclosing Circle in CSharp

From Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
Jump to navigation Jump to search

System Requirement

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

Stopwatch watch = Stopwatch.StartNew();
CircleF circle = PointCollection.MinEnclosingCircle(pts);

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

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