当前位置: 首页>>代码示例>>C#>>正文


C# Contour.ApproxPoly方法代码示例

本文整理汇总了C#中Contour.ApproxPoly方法的典型用法代码示例。如果您正苦于以下问题:C# Contour.ApproxPoly方法的具体用法?C# Contour.ApproxPoly怎么用?C# Contour.ApproxPoly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Contour的用法示例。


在下文中一共展示了Contour.ApproxPoly方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: findFingerTips

        private void findFingerTips(Contour<Point> bigContour, int scale)
        {
            Contour<Point> appContour = bigContour.ApproxPoly(bigContour.Perimeter * 0.0025, contourStorage);
            hull = bigContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
            defects = bigContour.GetConvexityDefacts(contourStorage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
            defectArray = defects.ToArray();

            int defectsTotal = defectArray.Count();
            if (defectsTotal > MAX_POINTS)
            {
                defectsTotal = MAX_POINTS;
            }

            // copy defect information from defects sequence into arrays
            for (int i = 0; i < defectsTotal; i++)
            {
                MCvConvexityDefect cdf = defectArray.ElementAt(i);
                Point startPt = cdf.StartPoint;
                Point endPt = cdf.EndPoint;
                Point depthPt = cdf.DepthPoint;

                double sx = startPt.X;
                double sy = startPt.Y;
                tipPts[i] = new Point((int)Math.Round(sx * scale), (int)Math.Round(sy * scale)); // array contains coords of the fingertips

                double dx = depthPt.X;
                double dy = depthPt.Y;
                foldPts[i] = new Point((int)Math.Round(dx * scale), (int)Math.Round(dy * scale)); //array contains coords of the skin fold between fingers
                depths[i] = cdf.Depth * scale; // array contains distances from tips to folds

                reduceTips(defectsTotal, tipPts, foldPts, depths);
            }
        }
开发者ID:hzhiguang,项目名称:AbuseAnalysis,代码行数:33,代码来源:HandDetector.cs

示例2: isRectangleByEdges

        bool isRectangleByEdges(Contour<Point> blob)
        {
            Contour<Point> approx = blob.ApproxPoly(blob.Perimeter * 0.05);
            Point[] pts = approx.ToArray();
            LineSegment2D[] edges = PointCollection.PolyLine(pts, true);

            if (approx.Total != 4)
                return false;

            for (int i = 0; i < edges.Length; i++)
            {
                double angle = Math.Abs(edges[(i + 1) % edges.Length].GetExteriorAngleDegree(edges[i]));
                if (angle < 80 || angle > 100)
                    return false;
            }
            return true;
        }
开发者ID:GreenBlitz4590Programmers,项目名称:StrongHoldVision,代码行数:17,代码来源:ImageProcessor.cs

示例3: FindStopSign

        private void FindStopSign(Image<Bgr, byte> img, List<Image<Gray, Byte>> stopSignList, List<Rectangle> boxList, Contour<Point> contours)
        {
            for (; contours != null; contours = contours.HNext)
             {
            contours.ApproxPoly(contours.Perimeter * 0.02, 0, contours.Storage);
            if (contours.Area > 200)
            {
               double ratio = CvInvoke.cvMatchShapes(_octagon, contours, Emgu.CV.CvEnum.CONTOURS_MATCH_TYPE.CV_CONTOURS_MATCH_I3, 0);

               if (ratio > 0.1) //not a good match of contour shape
               {
                  Contour<Point> child = contours.VNext;
                  if (child != null)
                     FindStopSign(img, stopSignList, boxList, child);
                  continue;
               }

               Rectangle box = contours.BoundingRectangle;

               Image<Gray, Byte> candidate;
               using (Image<Bgr, Byte> tmp = img.Copy(box))
                  candidate = tmp.Convert<Gray, byte>();

               //set the value of pixels not in the contour region to zero
               using (Image<Gray, Byte> mask = new Image<Gray, byte>(box.Size))
               {
                  mask.Draw(contours, new Gray(255), new Gray(255), 0, -1, new Point(-box.X, -box.Y));

                  double mean = CvInvoke.cvAvg(candidate, mask).v0;
                  candidate._ThresholdBinary(new Gray(mean), new Gray(255.0));
                  candidate._Not();
                  mask._Not();
                  candidate.SetValue(0, mask);
               }

               SURFFeature[] features = candidate.ExtractSURF(ref _surfParam);

               SURFTracker.MatchedSURFFeature[] matchedFeatures = _tracker.MatchFeature(features, 2, 20);

               int goodMatchCount = 0;
               foreach (SURFTracker.MatchedSURFFeature ms in matchedFeatures)
                  if (ms.SimilarFeatures[0].Distance < 0.5) goodMatchCount++;

               if (goodMatchCount >= 10)
               {
                  boxList.Add(box);
                  stopSignList.Add(candidate);
               }
            }
             }
        }
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:51,代码来源:StopSignDetector.cs

示例4: ProcesseFramesToFindSquares

        public void ProcesseFramesToFindSquares(Image<Bgr, Byte> pImage)
        {
            pbBad.Visible = false;
            pbGood.Visible = false;
            scala_x = (float)(pImage.Width * 1.0 / pictureBox1.Width);
            scala_y = (float)(pImage.Height * 1.0 / pictureBox1.Height);

            #region square
            if (pImage != null)
            {

                Image<Bgr, Byte> pImg = pImage.Copy();
                Image<Gray, Byte> gray = pImg.Convert<Gray, Byte>().PyrDown().PyrUp();
                ibHoughCircles.Image = null;
                ibHoughCircles.Image = gray;

                Gray cannyThreshold = new Gray(180);
                Gray cannyThresholdLinking = new Gray(120);

                Image<Gray, Byte> cannyEdges = gray.Canny(cannyThreshold, cannyThresholdLinking);
                ibHoughCircles2.Image = null;
                ibHoughCircles2.Image = cannyEdges;

                LineSegment2D[] lines = cannyEdges.HoughLinesBinary(1, Math.PI / 45.0, 20, 30, 10)[0];

                List<MCvBox2D> boxList = new List<MCvBox2D>();
                listSquares = new List<MCvBox2D>();
                int squares = 0;
                using (MemStorage storage = new MemStorage())
                {
                    for (Contour<Point> contours = cannyEdges.FindContours(); contours != null; contours = contours.HNext)
                    {
                        //Contour<Point> currentContour = contours.ApproxPoly(contours.Perimeter * 0.05, storage);
                        Contour<Point> currentContour = contours.ApproxPoly(contours.Perimeter * 0.05, storage);

                        if (contours.Area > 1000 )// Int32.Parse(txtTotalApplicants.Text))
                        {
                            if (currentContour.Total == 4 || currentContour.Total == 2 || currentContour.Total == 6)
                            {
                                bool isRectangle = true;
                                Point[] pts = currentContour.ToArray();
                                LineSegment2D[] edges = PointCollection.PolyLine(pts, true);
                                //using edges i found coordinates.
                                for (int i = 0; i < edges.Length; i++)
                                {
                                    double angle = Math.Abs(edges[(i + 1) % edges.Length].GetExteriorAngleDegree(edges[i]));
                                    if (angle < 85 || angle > 95)
                                    //if (angle < 80 || angle > 110)
                                    //if (angle != 90)
                                    {
                                        isRectangle = false;
                                        break;
                                    }
                                    if (isRectangle)
                                    {
                                        boxList.Add(currentContour.GetMinAreaRect());
                                        // added
                                        MCvBox2D box = contours.GetMinAreaRect();
                                        listSquares.Add(box);
                                        pImg.Draw(box, new Bgr(System.Drawing.Color.Red), 9);
                                        squares++;
                                    }
                                }
                            }
                        }
                    }
                }
                ibOriginal.Image = pImg;
                txtTotalApplicants.Text = listSquares.Count.ToString(); //squares.ToString();

                bool a, b, c, d;
                a = b = c = d = false;
                for (int i = 0; i < listSquares.Count; i++)
                {
                    //set the x,y position of the 4 squares guides of the scanned papaer
                    float xp = listSquares[i].center.X / scala_x;
                    float yp = listSquares[i].center.Y / scala_y;

                    if (listSquares[i].center.X < pImg.Width / 2 &&
                        listSquares[i].center.Y < pImg.Height / 2)
                    {
                        mayas_corner[3].circles[0].set_X(xp);
                        mayas_corner[3].circles[0].set_Y(yp);
                        a = true;
                    }
                    if (listSquares[i].center.X > pImg.Width / 2 &&
                        listSquares[i].center.Y < pImg.Height / 2)
                    {
                        mayas_corner[3].circles[1].set_X(xp);
                        mayas_corner[3].circles[1].set_Y(yp);
                        b = true;
                    }
                    if (listSquares[i].center.X < pImg.Width / 2 &&
                        listSquares[i].center.Y > pImg.Height / 2)
                    {
                        mayas_corner[3].circles[2].set_X(xp);
                        mayas_corner[3].circles[2].set_Y(yp);
                        c = true;
                    }
                    if (listSquares[i].center.X > pImg.Width / 2 &&
//.........这里部分代码省略.........
开发者ID:kevinmartell91,项目名称:ExamenPsicologico,代码行数:101,代码来源:Form1.cs

示例5: FindSign

        private List<SignResult> FindSign(Image<Bgr, byte> image, Contour<Point> contours)
        {
            List<SignResult> results =  new List<SignResult>();

            for (; contours != null; contours = contours.HNext)
            {
                contours.ApproxPoly(contours.Perimeter * 0.02, 0, contours.Storage);

                if (contours.Area > 200)
                {
                    double ratio = CvInvoke.cvMatchShapes(octagonContour, contours, Emgu.CV.CvEnum.CONTOURS_MATCH_TYPE.CV_CONTOURS_MATCH_I3, 0);

                    if (ratio > 0.05) //not a good match of contour shape
                    {
                        results.AddRange(FindSignInChildren(image, contours));
                    }
                    else
                    {
                        SignResult result = DetectSignInCurrentContour(image, contours);
                        if (result != null) { results.Add(result); }
                    }
                }
            }

            return results;
        }
开发者ID:abraxas4,项目名称:AR-Drone-Project,代码行数:26,代码来源:SignDetector.cs

示例6: detectAndDrawHand

        private bool detectAndDrawHand(Contour<Point> hand)
        {
            bool realHand = false;
            double first = 0;

            Contour<Point> currentContour = hand.ApproxPoly(hand.Perimeter * 0.0025, contourStorage);

            hull = currentContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
            box = currentContour.GetMinAreaRect();

            //Calculate the center of the hand
            PointF center = new PointF(box.center.X, box.center.Y);
            float centerX = box.center.X;
            float centerY = box.center.Y;

            //Find all defects in the contour
            defects = currentContour.GetConvexityDefacts(contourStorage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
            defectArray = defects.ToArray();

            if (defects != null)
            {
                List<double> tipDistance = new List<double>();

                for (int i = 0; i < defects.Total; i++)
                {
                    float sX = defectArray[i].StartPoint.X;
                    float sY = defectArray[i].StartPoint.Y;
                    double distance = (Math.Pow(sX - centerX, 2) + Math.Pow(sY - centerY, 2));
                    tipDistance.Add(distance);
                }

                for (int i = 0; i < tipDistance.Count(); i++)
                {
                    if (i == 0)
                    {
                        first = tipDistance.ElementAt(i);
                    }
                    else if (i > 0)
                    {
                        double difference = first - tipDistance.ElementAt(i);
                        if ((difference < 10) && (tipDistance.ElementAt(i) > -10))
                        {
                            realHand = true;
                        }
                    }
                }

                if (realHand == true)
                {
                    //Draw hand
                    drawHand(currentContour, center);

                    //Analysis hand gesture
                    string gesture = analysisHandGesture(center);
                    if ((gesture.Equals("Left Palm")) || (gesture.Equals("Left Fist")) || (gesture.Equals("Right Palm")) || (gesture.Equals("Right Fist")))
                    {
                        PointF newCenter = new PointF(centerX, centerY);
                        handMotionList.Add(skin);
                        motionPoints.Add(newCenter);
                        gestures.Add(gesture);
                        runTimes.Add(time / 1000);
                    }
                }
            }
            return realHand;
        }
开发者ID:hzhiguang,项目名称:AbuseAnalysis,代码行数:66,代码来源:Form1.cs

示例7: DetectFingers

        public void DetectFingers(Image<Gray, Byte> image)
        {
            /*
            Point3D ptHandProjective = this.depth.ConvertRealWorldToProjective(ptHand);
            Size offset = new Size((int)ptHandProjective.X, (int)ptHandProjective.Y);
            //get the hand
            Image<Gray, Byte> image = detector.DetectHand(this.depth, ptHand);
            */

            //image = image.PyrDown().PyrUp();
            //image._SmoothGaussian(5);
            //image._ThresholdBinary(new Gray(149), new Gray(255));

            Graphics g = Graphics.FromImage(this.bitmap);

            MemStorage storage1 = new MemStorage();

            Contour<Point> contours = new Contour<Point>(storage1);

            // Find the biggest contour
            for (Contour<Point> tempContours = image.FindContours(); tempContours != null; tempContours = tempContours.HNext)
            {
                if (tempContours.Area > contours.Area)
                    contours = tempContours;
            }

            //Console.WriteLine(contours.Area);
            if (contours.Area != 0)
            {
                List<KeyValuePair<Point, bool>> significantPts = new List<KeyValuePair<Point, bool>>();
                Rectangle contourRectangle = contours.BoundingRectangle;
                g.DrawRectangle(new Pen(Brushes.Green), contourRectangle);

                //Seq<Point> contoursHull = contours.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);

                // Convert the set of contour points to a polygon for graphical representation

                Seq<Point> poly = contours.ApproxPoly(20);
                Point[] polygon = poly.ToArray();

                PointF[] contourF = Array.ConvertAll(contours.ToArray(), new Converter<Point, PointF>(PointToPointF));
                //CircleF palmCircle = PointCollection.MinEnclosingCircle(contourF);
                //CircleF palmCircle = PointCollection.EllipseLeastSquareFitting(contourF);
                //MCvBox2D box = PointCollection.MinAreaRect(contourF);
                //g.DrawRectangle(new Pen(Brushes.Aquamarine),(Rectangle) box.MinAreaRect());
                //drawCircle(g, new Pen(Brushes.Green), PointFToPoint(palmCircle.Center), (int) Math.Round(palmCircle.Radius));

                // Get the convex hull based on the contour polygon
                Seq<Point> convexHull = poly.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);

                /*
                 * Handle opening and closing of the fist each frame.
                 * Fisting gesture controls the left mouse button.
                 * Based on the ratio of area between the convex and the hull.
                 * (See calculation above) Threshold currently set to 0.8
                 *
                 * NEED TO HAND COORDINATES
                 */
                double hullArea = convexHull.Area;
                double contourArea = contours.Area;
                double currentHullRatio = contourArea / hullArea;

                // newest ratio is in front of array
                hullRatios[2] = hullRatios[1];
                hullRatios[1] = hullRatios[0];
                hullRatios[0] = currentHullRatio;

                this.fixedHullRatio = hullRatios[2];

                if (smoothHullRatios && this.frame > 3)
                {
                    this.hullRatios = smoothHullRatioArray(this.hullRatios);
                }

                bool fistClosed = true;
                stopTracking = true;

                if (shouldHandClose())
                {
                    stopTracking = true;
                    fistClosed = false;
                }
                if (shouldControlMouse)
                {
                    //clickMouse(fistClosed);
                }

                // Get the convexity defects from the contour
                stopwatch.Restart();
                Seq<Emgu.CV.Structure.MCvConvexityDefect> contourDefects = contours.GetConvexityDefacts(storage1, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                stopwatch.Stop();
                //Console.WriteLine(Math.Round(1000.0 * (double)stopwatch.ElapsedTicks / Stopwatch.Frequency, 4) + ", GetConvexityDefacts()");

                // Draw the polygon that was converted from the contour
                /*
                for (int i = 0; i < polygon.Length; i++)
                {
                    if (i == polygon.Length - 1)
                        g.DrawLine((new Pen(Brushes.Blue))), polygon[i], polygon[0]);
                    else
//.........这里部分代码省略.........
开发者ID:faddison,项目名称:KMouse,代码行数:101,代码来源:MainWindow.cs

示例8: FindStopSign

        private void FindStopSign(Image<Bgr, byte> img, List<Image<Gray, Byte>> stopSignList, List<Rectangle> boxList, Contour<Point> contours)
        {
            for (; contours != null; contours = contours.HNext)
            {
                //draw box from any contour


                imageGray.Draw(new CircleF(centerBox(contours.BoundingRectangle), 3), new Gray(150), 2);
                contours.ApproxPoly(contours.Perimeter * 0.02, 0, contours.Storage);
                if (contours.Area > 20)
                {
                    double ratio = CvInvoke.cvMatchShapes(_octagon2, contours, Emgu.CV.CvEnum.CONTOURS_MATCH_TYPE.CV_CONTOURS_MATCH_I3, 0);

                    if (ratio > 0.1) //not a good match of contour shape
                    {
                        Contour<Point> child = contours.VNext;
                        if (child != null)
                            FindStopSign(img, stopSignList, boxList, child);
                        continue;
                    }
                    
                    Rectangle box = contours.BoundingRectangle;
                    
                    
                    Image<Gray, Byte> candidate;
                    using (Image<Bgr, Byte> tmp = img.Copy(box))
                        candidate = tmp.Convert<Gray, byte>();

                    //set the value of pixels not in the contour region to zero
                    using (Image<Gray, Byte> mask = new Image<Gray, byte>(box.Size))
                    {
                        mask.Draw(contours, new Gray(255), new Gray(255), 0, -1, new Point(-box.X, -box.Y));

                        double mean = CvInvoke.cvAvg(candidate, mask).v0;
                        candidate._ThresholdBinary(new Gray(mean), new Gray(255.0));
                        candidate._Not();
                        mask._Not();
                        candidate.SetValue(0, mask);
                    }

                    ImageFeature<float>[] features = _detector2.DetectFeatures(candidate, null);

                    Features2DTracker<float>.MatchedImageFeature[] matchedFeatures = _tracker2.MatchFeature(features, 2);

                    int goodMatchCount = 0;
                    foreach (Features2DTracker<float>.MatchedImageFeature ms in matchedFeatures)
                        if (ms.SimilarFeatures[0].Distance < 0.5) goodMatchCount++;

                    if (goodMatchCount >= 10)
                    {
                        //imageGray.Draw(contours, new Gray(150), 2);
                        imagecolor.Draw(contours, new Bgr(255,0,0), 2);
                        areas.Add(contours.Area);
                        boxList.Add(box);                                                

                        imageGray.Draw(contours.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE), new Gray(150), 2);
                        stopSignList.Add(candidate);
                    }
                }
            }
        }
开发者ID:petrind,项目名称:SRTesis2,代码行数:61,代码来源:SignDetector.cs

示例9: FindRect

        /// <summary>
        /// 
        /// </summary>
        /// <param name="img"></param>
        /// <param name="stopSignList"></param>
        /// <param name="boxList"></param>
        /// <param name="contours"></param>
        /// <param name="color">1=dark blue, 2 = pink, 3 = light green, 4 = purple, 5 = black, 6 = white</param>
        private void FindRect(Image<Bgr, byte> img, List<Image<Gray, Byte>> stopSignList, List<Rectangle> boxList, Contour<Point> contours, int color)
        {
            int i=0;
            MCvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 0.8, 0.8);
            for (; contours != null; contours = contours.HNext)
            {
                //draw box from any contour
                
                //imageGray.Draw(new CircleF(centerBox(contours.BoundingRectangle), 3), new Gray(150), 2);
                contours.ApproxPoly(contours.Perimeter * 0.02, 0, contours.Storage);
                
                if (contours.Area > 100 && contours.Total>0)
                {
                    
                    //handle normal rectangle
                    MCvBox2D minAreaRect = contours.GetMinAreaRect();

                    shapeRatio = CvInvoke.cvMatchShapes(rect, contours, Emgu.CV.CvEnum.CONTOURS_MATCH_TYPE.CV_CONTOURS_MATCH_I3, 0);
                    double areaRatio = areaSize(minAreaRect.size) / contours.Area;
                    PointF c = centerBox(contours.BoundingRectangle);
                     if (shapeRatio < 0.1 && areaRatio<1.2)
                    {
                        Rectangle box = contours.BoundingRectangle;
                        //imageGray.Draw(box, new Gray(150), 1);                        

                        //imageGray.Draw(contours, new Gray(50), 2);                        
                        imageGray.Draw("" + i, ref f, new Point((int)c.X, (int)c.Y), new Gray(200));
                        pointBlack[i] = c;
                        minBoxesBlack[i] = minAreaRect;
                        foreach (Point p in contours) joinContour.Push(p);
                        i++;
                        
                    }
                     //handle the rectangle with diferent orientation
                     else if (areaRatio < 1.3 && shapeRatio < 0.5)
                    {
                        Rectangle box = contours.BoundingRectangle;
                        //imageGray.Draw(box, new Gray(150), 1);
                        

                        //imageGray.Draw(contours, new Gray(50), 2);
                        
                        imageGray.Draw("" + i, ref f, new Point((int)c.X, (int)c.Y), new Gray(200));
                        pointBlack[i] = c;
                        minBoxesBlack[i] = minAreaRect;
                        i++;
                        foreach (Point p in contours) joinContour.Push(p);
                        
                    } else
                         imageGray.Draw("" + i, ref f, new Point((int)c.X, (int)c.Y), new Gray(100));

                     
                }
                
            }
            
        }
开发者ID:petrind,项目名称:SRTesis2,代码行数:65,代码来源:ShapeDetector.cs

示例10: FindColoredObject

        /// <summary>
        /// 
        /// </summary>
        /// <param name="img"></param>
        /// <param name="contours"></param>
        /// <param name="color">1=dark blue, 2 = pink, 3 = light green, 4 = purple, 5 = black, 6 = white</param>
        private void FindColoredObject(Image<Bgr, byte> img, Contour<Point> contours, int color)
        {
            for (; contours != null; contours = contours.HNext)
            {
                //draw box from any contour

                contours.ApproxPoly(contours.Perimeter * 0.02, 0, contours.Storage);
                if (contours.Area > 20)
                {
                    PointF c = centerBox(contours.BoundingRectangle);

                    imageGray.Draw(new CircleF(c, 3), new Gray(150), 2);
                    imageColor.Draw(new CircleF(c, 3), new Bgr(255, 255, 255), 1);
                    centerPoints.Add(c);

                    PointF pReal = new PointF();
                    float z = zCalc(2.4f, contours.BoundingRectangle.Width, 1);
                    pReal.X = (c.X * z - cxTop * z) / fxTop;
                    pReal.Y = (c.Y * z - cyTop * z) / fyTop;
                    colorObjects.Add(new colorObject(pReal.X,pReal.Y,z, color,contours.BoundingRectangle));

                    // detect the chessboard
                    Gray_Frame = img.Convert<Gray, Byte>();//
                }
            }
        }
开发者ID:petrind,项目名称:SRTesis2,代码行数:32,代码来源:PointDetector.cs

示例11: FindRect

        /// <summary>
        /// 
        /// </summary>
        /// <param name="img"></param>
        /// <param name="contours"></param>
        /// <param name="color">1=dark blue, 2 = pink, 3 = light green, 4 = purple, 5 = black, 6 = white</param>
        private void FindRect(Image<Bgr, byte> img, Contour<Point> contours, int color)
        {
            int i = 0;
            MCvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 0.8, 0.8);
            for (; contours != null; contours = contours.HNext)
            {
                contours.ApproxPoly(contours.Perimeter * 0.02, 0, contours.Storage);

                if (contours.Area > 100 && contours.Total > 0)
                {
                    MCvBox2D minAreaRect = contours.GetMinAreaRect();

                    shapeRatio = CvInvoke.cvMatchShapes(rect, contours, Emgu.CV.CvEnum.CONTOURS_MATCH_TYPE.CV_CONTOURS_MATCH_I3, 0);
                    double areaRatio = areaSize(minAreaRect.size) / contours.Area;
                    PointF c = centerBox(contours.BoundingRectangle);
                    if (shapeRatio < 0.1 && areaRatio < 1.2)
                    {
                        Rectangle box = contours.BoundingRectangle;
                        pointBlack[i] = c;
                        minBoxesBlack[i] = minAreaRect;
                        i++;

                    }
                    //handle the rectangle with diferent orientation
                    else if (areaRatio < 1.3 && shapeRatio < 0.5)
                    {
                        Rectangle box = contours.BoundingRectangle;
                        pointBlack[i] = c;
                        minBoxesBlack[i] = minAreaRect;
                        i++;
                    }
                    else
                        imageGray.Draw("" + i, ref f, new Point((int)c.X, (int)c.Y), new Gray(100));
                }
            }
        }
开发者ID:petrind,项目名称:SRTesis2,代码行数:42,代码来源:PointDetector.cs


注:本文中的Contour.ApproxPoly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。