Difference between revisions of "Convex Hull in CSharp"

From Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
Jump to: navigation, search
(Undo revision 996 by Inuxejiq (talk))
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://ewefobyme.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]=
 
----
 
=[http://ewefobyme.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 17: Line 9:
  
 
== Source Code ==
 
== Source Code ==
&lt;source lang="csharp">
+
<source lang="csharp">
 
#region Create some random points
 
#region Create some random points
 
Random r = new Random();
 
Random r = new Random();
 
PointF[] pts = new PointF[200];
 
PointF[] pts = new PointF[200];
for (int i = 0; i &lt; pts.Length; i++)
+
for (int i = 0; i < pts.Length; i++)
 
{
 
{
 
   pts[i] = new PointF((float)(100 + r.NextDouble() * 400), (float)(100 + r.NextDouble() * 400));
 
   pts[i] = new PointF((float)(100 + r.NextDouble() * 400), (float)(100 + r.NextDouble() * 400));
Line 27: Line 19:
 
#endregion
 
#endregion
  
Image&lt;Bgr, Byte> img = new Image&lt;Bgr, byte>(600, 600, new Bgr(255.0, 255.0, 255.0));
+
Image<Bgr, Byte> img = new Image<Bgr, byte>(600, 600, new Bgr(255.0, 255.0, 255.0));
 
//Draw the points  
 
//Draw the points  
 
foreach (PointF p in pts)
 
foreach (PointF p in pts)
Line 39: Line 31:
 
   watch.Stop();
 
   watch.Stop();
 
   img.DrawPolyline(
 
   img.DrawPolyline(
       Array.ConvertAll&lt;PointF, Point>(hull, Point.Round),
+
       Array.ConvertAll<PointF, Point>(hull, Point.Round),
 
       true, new Bgr(255.0, 0.0, 0.0), 1);
 
       true, new Bgr(255.0, 0.0, 0.0), 1);
  
 
   ImageViewer.Show(img, String.Format("Convex Hull Computed in {0} milliseconds", watch.ElapsedMilliseconds));
 
   ImageViewer.Show(img, String.Format("Convex Hull Computed in {0} milliseconds", watch.ElapsedMilliseconds));
 
}
 
}
&lt;/source>
+
</source>
  
 
== Result ==
 
== Result ==
 
[[image:ConvexHullExample.png]]
 
[[image:ConvexHullExample.png]]

Revision as of 04:13, 24 November 2010

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

Result

ConvexHullExample.png