Beispiel #1
0
        public void TestSeqPerformance()
        {
            Point[] pts = new Point[1000000];

             using (MemStorage stor = new MemStorage())
             {
            Stopwatch watch = Stopwatch.StartNew();
            Seq<Point> seq = new Seq<Point>(stor);
            seq.PushMulti(pts, Emgu.CV.CvEnum.BACK_OR_FRONT.FRONT);
            watch.Stop();
            Trace.WriteLine(String.Format("Time for storing {0} points: {1} milliseconds", pts.Length, watch.ElapsedMilliseconds));

            watch.Reset(); watch.Start();
            int counter = 0;
            foreach (Point p in seq)
            {
               counter++;
            }
            watch.Stop();
            Trace.WriteLine(String.Format("Time for reading {0} points: {1} milliseconds", pts.Length, watch.ElapsedMilliseconds));

             }
        }
Beispiel #2
0
        public void TestConvexityDefacts()
        {
            Image<Gray, Byte> image = new Image<Gray, byte>(300, 300);
             Point[] polyline = new Point[] {
            new Point(10, 10),
            new Point(10, 250),
            new Point(100, 100),
            new Point(250, 250),
            new Point(250, 10)};

             using (MemStorage stor = new MemStorage())
             {
            Seq<Point> contour = new Seq<Point>(stor);
            contour.PushMulti(polyline, Emgu.CV.CvEnum.BACK_OR_FRONT.FRONT);
            image.Draw(contour, new Gray(255), 1);
            Seq<MCvConvexityDefect> defactSeq =
               contour.GetConvexityDefacts(
                  stor,
                  Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
            MCvConvexityDefect[] defacts = defactSeq.ToArray();
            Assert.AreEqual(1, defacts.Length);
            Assert.AreEqual(new Point(100, 100), defacts[0].DepthPoint);

            Assert.IsTrue(contour.InContour(new PointF(90, 90)) > 0);
            Assert.IsTrue(contour.InContour(new PointF(300, 300)) < 0);
            Assert.IsTrue(contour.InContour(new PointF(10, 10)) == 0);
             }
        }
        public Seq<Point> GetConvexHull(List<Contour<Point>> contourPoints)
        {
            Seq<Point> hullPoints = new Seq<Point>(new MemStorage());
            foreach (Seq<Point> countoure in contourPoints)
            {
                hullPoints.PushMulti(countoure.ToArray(), BACK_OR_FRONT.FRONT);
            }

            hullPoints = hullPoints.GetConvexHull(ORIENTATION.CV_COUNTER_CLOCKWISE);
            return hullPoints;
        }