Convex Hull in CSharp: Difference between revisions
Jump to navigation
Jump to search
Created page with '== System Requirement == {| style="text-align:center" border="1px" cellpadding="10" cellspacing="0" !Component || Requirement || Detail |- |Emgu CV || Version 1.5 || |- |Operati…' |
|||
Line 10: | Line 10: | ||
== Source Code == | == Source Code == | ||
<source lang="csharp"> | <source lang="csharp"> | ||
#region Create some random points | #region Create some random points | ||
Random r = new Random(); | Random r = new Random(); |
Revision as of 18:59, 20 August 2009
System Requirement
Component | Requirement | Detail |
---|---|---|
Emgu CV | Version 1.5 | |
Operation System | Cross Platform |
Source Code
#region Create some random points
Random r = new Random();
PointF[] pts = new PointF[200];
for (int i = 0; i < pts.Length; i++)
{
pts[i] = new PointF((float)(100 + r.NextDouble() * 400), (float)(100 + r.NextDouble() * 400));
}
#endregion
Image<Bgr, Byte> img = new Image<Bgr, byte>(600, 600, new Bgr(255.0, 255.0, 255.0));
//Draw the points
foreach (PointF p in pts)
img.Draw(new CircleF(p, 3), new Bgr(0.0, 0.0, 0.0), 1);
//Find and draw the convex hull
using (MemStorage storage = new MemStorage())
{
Stopwatch watch = Stopwatch.StartNew();
PointF[] hull = PointCollection.ConvexHull(pts, storage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE).ToArray();
watch.Stop();
img.DrawPolyline(
Array.ConvertAll<PointF, Point>(hull, Point.Round),
true, new Bgr(255.0, 0.0, 0.0), 1);
ImageViewer.Show(img, String.Format("Convex Hull Computed in {0} milliseconds", watch.ElapsedMilliseconds));
}