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


C# Seq.Push方法代码示例

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


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

示例1: TestContourCreate

        public void TestContourCreate()
        {
            using (MemStorage stor = new MemStorage())
             {
            Contour<Point> contour = new Contour<Point>(stor);
            contour.Push(new Point(0, 0));
            contour.Push(new Point(0, 2));
            contour.Push(new Point(2, 2));
            contour.Push(new Point(2, 0));
            Assert.IsTrue(contour.Convex);
            Assert.AreEqual(contour.Area, 4.0);
            //InContour function requires MCvContour.rect to be pre-computed
            CvInvoke.cvBoundingRect(contour, 1);
            Assert.GreaterOrEqual(contour.InContour(new Point(1, 1)), 0);
            Assert.Less(contour.InContour(new Point(3, 3)), 0);

            Contour<PointF> contourF = new Contour<PointF>(stor);
            contourF.Push(new PointF(0, 0));
            contourF.Push(new PointF(0, 2));
            contourF.Push(new PointF(2, 2));
            contourF.Push(new PointF(2, 0));
            Assert.IsTrue(contourF.Convex);
            Assert.AreEqual(contourF.Area, 4.0);
            //InContour function requires MCvContour.rect to be pre-computed
            CvInvoke.cvBoundingRect(contourF, 1);
            Assert.GreaterOrEqual(contourF.InContour(new PointF(1, 1)), 0);
            Assert.Less(contourF.InContour(new PointF(3, 3)), 0);

            Contour<MCvPoint2D64f> contourD = new Contour<MCvPoint2D64f>(stor);
            contourD.Push(new MCvPoint2D64f(0, 0));
            contourD.Push(new MCvPoint2D64f(0, 2));
            contourD.Push(new MCvPoint2D64f(2, 2));
            contourD.Push(new MCvPoint2D64f(2, 0));
            //Assert.IsTrue(contourD.Convex);
            //Assert.AreEqual(contourD.Area, 4.0);
            //InContour function requires MCvContour.rect to be pre-computed
            //CvInvoke.cvBoundingRect(contourD, 1);
            //Assert.GreaterOrEqual(contourD.InContour(new PointF(1, 1)), 0);
            //Assert.Less(contourD.InContour(new PointF(3, 3)), 0);

            Seq<Point> seq = new Seq<Point>(CvInvoke.CV_MAKETYPE(4, 2), stor);
            seq.Push(new Point(0, 0));
            seq.Push(new Point(0, 1));
            seq.Push(new Point(1, 1));
            seq.Push(new Point(1, 0));
             }
        }
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:47,代码来源:AutoTestVarious.cs

示例2: ExtractContourAndHull

        private void ExtractContourAndHull(Image<Gray, byte> skin)
        {
            List<Contour<Point>> contourList = new List<Contour<Point>>();
            Contour<Point> contours = skin.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, contourStorage);
            Contour<Point> biggestContour = null;

            Double current = 0;
            Double largest = 0;

            while (contours != null)
            {
                current = contours.Area;
                if (current > largest)
                {
                    largest = current;
                    biggestContour = contours;
                }
                contours = contours.HNext;
            }

            if (biggestContour != null)
            {
                //currentFrame.Draw(biggestContour, new Bgr(Color.DarkViolet), 2);
                Contour<Point> currentContour = biggestContour.ApproxPoly(biggestContour.Perimeter * 0.0025, contourStorage);
                currentFrame.Draw(currentContour, new Bgr(System.Drawing.Color.LimeGreen), 2);
                biggestContour = currentContour;

                hull = biggestContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                box = biggestContour.GetMinAreaRect();
                PointF[] points = box.GetVertices();
                //handRect = box.MinAreaRect();
                //currentFrame.Draw(handRect, new Bgr(200, 0, 0), 1);

                Point[] ps = new Point[points.Length];
                for (int i = 0; i < points.Length; i++)
                    ps[i] = new Point((int)points[i].X, (int)points[i].Y);

                currentFrame.DrawPolyline(hull.ToArray(), true, new Bgr(200, 125, 75), 2);
                currentFrame.Draw(new CircleF(new PointF(box.center.X, box.center.Y), 3), new Bgr(200, 125, 75), 2);

                //ellip.MCvBox2D= CvInvoke.cvFitEllipse2(biggestContour.Ptr);
                //currentFrame.Draw(new Ellipse(ellip.MCvBox2D), new Bgr(Color.LavenderBlush), 3);

                PointF center;
                float radius;
                //CvInvoke.cvMinEnclosingCircle(biggestContour.Ptr, out  center, out  radius);
                //currentFrame.Draw(new CircleF(center, radius), new Bgr(System.Drawing.Color.Gold), 2);

                //currentFrame.Draw(new CircleF(new PointF(ellip.MCvBox2D.center.X, ellip.MCvBox2D.center.Y), 3), new Bgr(100, 25, 55), 2);
                //currentFrame.Draw(ellip, new Bgr(Color.DeepPink), 2);

                //CvInvoke.cvEllipse(currentFrame, new Point((int)ellip.MCvBox2D.center.X, (int)ellip.MCvBox2D.center.Y), new System.Drawing.Size((int)ellip.MCvBox2D.size.Width, (int)ellip.MCvBox2D.size.Height), ellip.MCvBox2D.angle, 0, 360, new MCvScalar(120, 233, 88), 1, Emgu.CV.CvEnum.LINE_TYPE.EIGHT_CONNECTED, 0);
                //currentFrame.Draw(new Ellipse(new PointF(box.center.X, box.center.Y), new SizeF(box.size.Height, box.size.Width), box.angle), new Bgr(0, 0, 0), 2);

                filteredHull = new Seq<Point>(contourStorage);
                for (int i = 0; i < hull.Total; i++)
                {
                    if (Math.Sqrt(Math.Pow(hull[i].X - hull[i + 1].X, 2) + Math.Pow(hull[i].Y - hull[i + 1].Y, 2)) > box.size.Width / 10)
                    {
                        filteredHull.Push(hull[i]);
                    }
                }

                defects = biggestContour.GetConvexityDefacts(contourStorage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);

                defectArray = defects.ToArray();
            }
        }
开发者ID:hzhiguang,项目名称:AbuseAnalysis,代码行数:68,代码来源:Form1.cs

示例3: FindContourAndConvexHull

        private void FindContourAndConvexHull(Image<Gray, byte> skin, Image<Bgr, byte> imageFrame)
        {
            using (MemStorage cacheStorage = new MemStorage())
            {
                //getting the countours by simplest algorithm and list in retourn (tree isn't necessary)
                Contour<Point> contours = skin.FindContours(
                    Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
                    Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST,
                    cacheStorage
                );

                //this variable will contain the biggest countour (if any avaiable)
                Contour<Point> largestContour = null;

                //searching for biggest countour
                Double CurrArea = 0, MaxArea = 0;
                while (contours != null)
                {
                    CurrArea = contours.Area;
                    if (CurrArea > MaxArea)
                    {
                        MaxArea = CurrArea;
                        largestContour = contours;
                    }
                    contours = contours.HNext;
                }

                if (largestContour != null)
                {
                    //drawing oryginal countour on image:
                    imageFrame.Draw(largestContour, new Bgr(Color.DarkViolet), 2);

                    //smoothing a bit the countour to make less amout of defects + draw:
                    Contour<Point> currentContour = largestContour.ApproxPoly(largestContour.Perimeter * 0.0025, cacheStorage);
                    imageFrame.Draw(currentContour, new Bgr(Color.LimeGreen), 2);
                    largestContour = currentContour;

                    //computing and drawing convex hull (smallest polygon that covers whole hand):
                    hull = largestContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                    imageFrame.DrawPolyline(hull.ToArray(), true, new Bgr(200, 125, 75), 2);

                    //computing smallest box (with angle), that covers the hull, and drawing without angle:
                    box = largestContour.GetMinAreaRect();
                    handRect = box.MinAreaRect();
                    imageFrame.Draw(handRect, new Bgr(200, 0, 0), 1);

                    //drawing the center of the box iwth hull:
                    imageFrame.Draw(new CircleF(new PointF(box.center.X, box.center.Y), 3), new Bgr(200, 125, 75), 2);

                    //drawing ellipse ("E") that containts most of the foun pixels:
                    if (largestContour.Count() >= 5)
                    {
                        ellip.MCvBox2D = CvInvoke.cvFitEllipse2(largestContour.Ptr);
                        imageFrame.Draw(new Ellipse(ellip.MCvBox2D), new Bgr(Color.LavenderBlush), 3);
                    }

                    //computing and drawing minimal enclosing circle, that contains whole contour:
                    PointF center;
                    float radius;
                    CvInvoke.cvMinEnclosingCircle(largestContour.Ptr, out  center, out  radius);
                    imageFrame.Draw(new CircleF(center, radius), new Bgr(Color.Gold), 2);

                    //drawing center of ellipse "E":
                    imageFrame.Draw(new CircleF(new PointF(ellip.MCvBox2D.center.X, ellip.MCvBox2D.center.Y), 3), new Bgr(100, 25, 55), 2);
                    imageFrame.Draw(ellip, new Bgr(Color.DeepPink), 2);

                    //computing and drawing ellipse ("F") that shows the direction of hand:
                    CvInvoke.cvEllipse(imageFrame,
                        new Point((int)ellip.MCvBox2D.center.X, (int)ellip.MCvBox2D.center.Y),
                        new Size((int)ellip.MCvBox2D.size.Width, (int)ellip.MCvBox2D.size.Height),
                        ellip.MCvBox2D.angle,
                        0,
                        360,
                        new MCvScalar(120, 233, 88),
                        1,
                        Emgu.CV.CvEnum.LINE_TYPE.EIGHT_CONNECTED,
                        0);

                    //drawing ellipse, that's small, but also shows the direction of hand:
                    imageFrame.Draw(
                        new Ellipse(
                            new PointF(box.center.X, box.center.Y),
                            new SizeF(box.size.Height, box.size.Width),
                            box.angle),
                        new Bgr(0, 0, 0), 2);

                    //algorithm that fiters convex hull. It saves only those points, that have distance
                    //between next point bigger than 1/10th of the box size. Small ones are removed.
                    filteredHull = new Seq<Point>(cacheStorage);
                    for (int i = 0; i < hull.Total; i++)
                    {
                        if (Math.Sqrt(Math.Pow(hull[i].X - hull[i + 1].X, 2) + Math.Pow(hull[i].Y - hull[i + 1].Y, 2)) > box.size.Width / 10)
                        {
                            filteredHull.Push(hull[i]);
                        }
                    }

                    //finding convex hull defects:
                    defects = largestContour.GetConvexityDefacts(cacheStorage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                    defectsArr = defects.ToArray();
//.........这里部分代码省略.........
开发者ID:TBruzdzinski,项目名称:mmcv-handCTRL,代码行数:101,代码来源:Form1.cs

示例4: BinaryExpression

 private Expression BinaryExpression(bool noIn, ref bool isLHS)
 {
     var e = UnaryExpression(ref isLHS);
     var stack = new Seq<SREntry>();
     while (true)
     {
         var op = default(BinaryOperator);
         switch (Current.Tag)
         {
             case InputElementTag.Times:
                 op = new BinaryOperator(Current.Loc, BinaryOp.Times);
                 break;
             case InputElementTag.Slash:
                 op = new BinaryOperator(Current.Loc, BinaryOp.Div);
                 break;
             case InputElementTag.Percent:
                 op = new BinaryOperator(Current.Loc, BinaryOp.Mod);
                 break;
             case InputElementTag.Plus:
                 op = new BinaryOperator(Current.Loc, BinaryOp.Plus);
                 break;
             case InputElementTag.Minus:
                 op = new BinaryOperator(Current.Loc, BinaryOp.Minus);
                 break;
             case InputElementTag.LTLT:
                 op = new BinaryOperator(Current.Loc, BinaryOp.LeftShift);
                 break;
             case InputElementTag.GTGT:
                 op = new BinaryOperator(Current.Loc, BinaryOp.RightShift);
                 break;
             case InputElementTag.GTGTGT:
                 op = new BinaryOperator(Current.Loc, BinaryOp.UnsignedRightShift);
                 break;
             case InputElementTag.LT:
                 op = new BinaryOperator(Current.Loc, BinaryOp.LessThan);
                 break;
             case InputElementTag.GT:
                 op = new BinaryOperator(Current.Loc, BinaryOp.GreaterThan);
                 break;
             case InputElementTag.LTEq:
                 op = new BinaryOperator(Current.Loc, BinaryOp.LessThanOrEqual);
                 break;
             case InputElementTag.GTEq:
                 op = new BinaryOperator(Current.Loc, BinaryOp.GreaterThanOrEqual);
                 break;
             case InputElementTag.Instanceof:
                 op = new BinaryOperator(Current.Loc, BinaryOp.InstanceOf);
                 break;
             case InputElementTag.In:
                 if (!noIn)
                     op = new BinaryOperator(Current.Loc, BinaryOp.In);
                 break;
             case InputElementTag.EqEq:
                 op = new BinaryOperator(Current.Loc, BinaryOp.Equals);
                 break;
             case InputElementTag.BangEq:
                 op = new BinaryOperator(Current.Loc, BinaryOp.NotEquals);
                 break;
             case InputElementTag.EqEqEq:
                 op = new BinaryOperator(Current.Loc, BinaryOp.StrictEquals);
                 break;
             case InputElementTag.BangEqEq:
                 op = new BinaryOperator(Current.Loc, BinaryOp.StrictNotEquals);
                 break;
             case InputElementTag.Amp:
                 op = new BinaryOperator(Current.Loc, BinaryOp.BitwiseAND);
                 break;
             case InputElementTag.Hat:
                 op = new BinaryOperator(Current.Loc, BinaryOp.BitwiseXOR);
                 break;
             case InputElementTag.Bar:
                 op = new BinaryOperator(Current.Loc, BinaryOp.BitwiseOR);
                 break;
             case InputElementTag.AmpAmp:
                 op = new BinaryOperator(Current.Loc, BinaryOp.LogicalAND);
                 break;
             case InputElementTag.BarBar:
                 op = new BinaryOperator(Current.Loc, BinaryOp.LogicalOR);
                 break;
             default:
                 break;
         }
         if (op == null)
         {
             while (stack.Count > 0)
                 Reduce(ref e, stack);
             return e;
         }
         else
         {
             isLHS = false;
             Consume();
             var dummy = true;
             var r = UnaryExpression(ref dummy);
             while (stack.Count > 0 && stack.Peek().Op.Precedence >= op.Precedence)
                 Reduce(ref e, stack);
             stack.Push(new SREntry() { Op = op, Exp = r });
         }
     }
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:100,代码来源:Parser.cs

示例5: CalculateConvexityDefacts

        private Image<Gray, Byte> CalculateConvexityDefacts(Image<Gray, Byte> image)
        {
            Gray cannyThreshold = new Gray(80);
            Gray cannyThresholdLinking = new Gray(80);

            //image = image.Canny(cannyThreshold, cannyThresholdLinking);
            image = image.ThresholdBinary(cannyThreshold, cannyThresholdLinking);
            //image = image.Erode(1);
            //image = image.SmoothBilatral(1, 1, 1);
            //image = image.SmoothMedian(5);
            //image = image.SmoothBlur(1,1);
            using (MemStorage storage = new MemStorage())
            {

                Contour<Point> contours = image.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage);
                Contour<Point> biggestContour = null;

                Double Result1 = 0;
                Double Result2 = 0;

                //takes the biggest contour to track (not really relevant if u paint only the hand.)
                while (contours != null)
                {
                    Result1 = contours.Area;
                    if (Result1 > Result2)
                    {
                        Result2 = Result1;
                        biggestContour = contours;
                    }
                    contours = contours.HNext;
                }
                double contourArea = biggestContour.Area;

                if (biggestContour != null)
                {
                    //Drawing the contour of the hand
                    Contour<Point> currentContour = biggestContour.ApproxPoly(biggestContour.Perimeter * 0.0025, storage);
                    image.Draw(currentContour, new Gray(250), 1);

                    biggestContour = currentContour;

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

                    PointF[] points = box.GetVertices();
                    Point[] ps = new Point[points.Length];

                    for (int i = 0; i < points.Length; i++)
                    {
                        ps[i] = new Point((int)points[i].X, (int)points[i].Y);
                    }

                    image.DrawPolyline(hull.ToArray(), true, new Gray(255), 1);
                    image.Draw(new CircleF(new PointF(box.center.X, box.center.Y), 2), new Gray(255), 1);

                    filteredHull = new Seq<Point>(storage);
                    for (int i = 0; i < hull.Total; i++)
                    {
                        if (Math.Sqrt(Math.Pow(hull[i].X - hull[i + 1].X, 2) + Math.Pow(hull[i].Y - hull[i + 1].Y, 2)) > box.size.Width / 10)
                        {
                            filteredHull.Push(hull[i]);
                        }
                    }

                    defects = biggestContour.GetConvexityDefacts(storage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                    defectArray = defects.ToArray();
                }
            }
            return image;
        }
开发者ID:faddison,项目名称:KMouse,代码行数:70,代码来源:MainWindow.cs

示例6: LeftHandSideExpression

 private Expression LeftHandSideExpression()
 {
     var newStack = new Seq<InputElement>();
     while (Current.Tag == InputElementTag.New)
     {
         newStack.Push(Current);
         Consume();
     }
     var e = PrimaryExpression();
     var f = default(Expression);
     while ((f = LeftHandSideFollow(newStack, e)) != null)
         e = f;
     while (newStack.Count > 0)
         e = PopNew(newStack, e);
     return e;
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:16,代码来源:Parser.cs

示例7: UnaryExpression

 private Expression UnaryExpression(ref bool isLHS)
 {
     var stack = new Seq<UnaryOperator>();
     while (true)
     {
         switch (Current.Tag)
         {
             case InputElementTag.Delete:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.Delete));
                 Consume();
                 break;
             case InputElementTag.Void:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.Void));
                 Consume();
                 break;
             case InputElementTag.Typeof:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.TypeOf));
                 Consume();
                 break;
             case InputElementTag.PlusPlus:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.PreIncrement));
                 Consume();
                 break;
             case InputElementTag.MinusMinus:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.PreDecrement));
                 Consume();
                 break;
             case InputElementTag.Plus:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.UnaryPlus));
                 Consume();
                 break;
             case InputElementTag.Minus:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.UnaryMinus));
                 Consume();
                 break;
             case InputElementTag.Twiddle:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.BitwiseNot));
                 Consume();
                 break;
             case InputElementTag.Bang:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.LogicalNot));
                 Consume();
                 break;
             default:
             {
                 var e = PostfixExpression(ref isLHS);
                 while (stack.Count > 0)
                 {
                     isLHS = false;
                     var op = stack.Pop();
                     e = new UnaryExpression(op.Loc.Union(e.Loc), op, e);
                 }
                 return e;
             }
         }
     }
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:57,代码来源:Parser.cs

示例8: ExtractHull

        // Extrait la "coque" du contour et les verticles afin de pouvoir calculer plus tard le nombre de doigts détectés
        // Ce code vient en partie de ce projet : https://www.youtube.com/watch?v=Fjj9gqTCTfc
        public void ExtractHull()
        {
            try
            {
                // Récupère la "coque" du plus grand contour ainsi que le rectangle qui l'englobe
                hull = biggestContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                box = biggestContour.GetMinAreaRect();

                // Récupère les vertexes de la box
                PointF[] points = box.GetVertices();

                // On va créer un tableau de "Point" avec tous les points trouvés par "GetVerticles"
                Point[] ps = new Point[points.Length];
                for (int i = 0; i < points.Length; i++)
                {
                    ps[i] = new Point((int)points[i].X, (int)points[i].Y);
                }

                // Dessine la "coque" (qui entoure tous les verticles) en rouge sur l'image traitée
                imgProc.DrawPolyline(hull.ToArray(), true, new Bgr(Color.Red), 2);

                // Dessine un cercle bleu au centre de la box
                imgProc.Draw(new CircleF(new PointF(box.center.X, box.center.Y), 5), new Bgr(Color.Blue), 2);

                // Va filtrer les points de la "coque" afin de ne garder que ceux qui sont vraiment utiles
                filteredHull = new Seq<Point>(hullStorage);
                for (int i = 0; i < hull.Total; i++)
                {
                    if (Math.Sqrt(Math.Pow(hull[i].X - hull[i + 1].X, 2) + Math.Pow(hull[i].Y - hull[i + 1].Y, 2)) > box.size.Width / 10)
                    {
                        filteredHull.Push(hull[i]);
                    }
                }

                defects = biggestContour.GetConvexityDefacts(hullStorage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);

                defectArray = defects.ToArray();
            } catch(Exception ex) {
                return;
            }
        }
开发者ID:leeroybrun,项目名称:HEIGVD_HandDetection,代码行数:43,代码来源:HandDetection.cs

示例9: ExtractContourAndHull

        private void ExtractContourAndHull(Image<Gray, byte> skin)
        {
            using (MemStorage storage = new MemStorage())
            {

                Contour<Point> contours = skin.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage);
                Contour<Point> biggestContour = null;

                Double Result1 = 0;
                Double Result2 = 0;
                while (contours != null)
                {
                    Result1 = contours.Area;
                    if (Result1 > Result2)
                    {
                        Result2 = Result1;
                        biggestContour = contours;
                    }
                    contours = contours.HNext;
                }

                if (biggestContour != null)
                {
                    //currentFrame.Draw(biggestContour, new Bgr(Color.DarkViolet), 2);
                    Contour<Point> currentContour = biggestContour.ApproxPoly(biggestContour.Perimeter * 0.0025, storage);
                    currentFrame.Draw(currentContour, new Bgr(Color.LimeGreen), 2);
                    biggestContour = currentContour;
                    hull = biggestContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                    box = biggestContour.GetMinAreaRect();
                    PointF[] points = box.GetVertices();
                    mv = biggestContour.GetMoments();
                    CvInvoke.cvMoments(biggestContour,ref mv, 1);
                    double m00 = CvInvoke.cvGetSpatialMoment(ref mv, 0, 0) ;
                    double m10 = CvInvoke.cvGetSpatialMoment(ref mv, 1, 0) ;
                    double m01 = CvInvoke.cvGetSpatialMoment(ref mv, 0, 1) ;
                    if (m00 != 0) { // calculate center
                    int xCenter = (int) Math.Round(m10/m00)*2;  //scale = 2
                    int yCenter = (int) Math.Round(m01/m00)*2;
                    cogPt.X =xCenter;
                    cogPt.Y =yCenter;
                    }

                    double m11 = CvInvoke.cvGetCentralMoment(ref mv, 1, 1);
                    double m20 = CvInvoke.cvGetCentralMoment(ref mv, 2, 0);
                    double m02 = CvInvoke.cvGetCentralMoment(ref mv, 0, 2);
                    contourAxisAngle = calculateTilt(m11, m20, m02);
                    Point[] ps = new Point[points.Length];
                    for (int i = 0; i < points.Length; i++)
                        ps[i] = new Point((int)points[i].X, (int)points[i].Y);

                    currentFrame.DrawPolyline(hull.ToArray(), true, new Bgr(200, 125, 75), 2);
                    currentFrame.Draw(new CircleF(new PointF(box.center.X, box.center.Y), 3), new Bgr(200, 125, 75), 2);

                    filteredHull = new Seq<Point>(storage);
                    for (int i = 0; i < hull.Total; i++)
                    {
                        if (Math.Sqrt(Math.Pow(hull[i].X - hull[i + 1].X, 2) + Math.Pow(hull[i].Y - hull[i + 1].Y, 2)) > box.size.Width / 10)
                        {
                            filteredHull.Push(hull[i]);
                        }
                    }

                    defects = biggestContour.GetConvexityDefacts(storage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                    defectArray = defects.ToArray();
                }
            }
        }
开发者ID:abhishek-rs,项目名称:Gesture-based-picture-viewer,代码行数:67,代码来源:Form1.cs

示例10: ExtractContourAndHull

        private void ExtractContourAndHull(Image<Gray, byte> skin)
        {
            using (MemStorage storage = new MemStorage())
            {

                Contour<Point> contours = skin.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage);
                Contour<Point> biggestContour = null;

                Double Result1 = 0;
                Double Result2 = 0;
                while (contours != null)
                {
                    Result1 = contours.Area;
                    if (Result1 > Result2)
                    {
                        Result2 = Result1;
                        biggestContour = contours;
                    }
                    contours = contours.HNext;
                }

                if (biggestContour != null)
                {
                   // currentFrame.Draw(biggestContour, new Bgr(Color.Black), 2);
                    Contour<Point> currentContour = biggestContour.ApproxPoly(biggestContour.Perimeter * 0.0025, storage);
                    //currentFrame.Draw(currentContour, new Bgr(Color.Red), 2);
                    biggestContour = currentContour;

                    hull = biggestContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                    box = biggestContour.GetMinAreaRect();
                    PointF[] points = box.GetVertices();
                    handRect = box.MinAreaRect();
                    //int xx = (handRect.Width) / 2;
                    //int yy = (handRect.Height) / 2;
                    currentFrame.Draw(handRect, new Bgr(200, 0, 0), 1);

                    // currentFrame.Draw(new CircleF(new PointF(xx, yy), 3), new Bgr(200, 125, 75), 2);
                    Point[] ps = new Point[points.Length];
                    for (int i = 0; i < points.Length; i++)
                        ps[i] = new Point((int)points[i].X, (int)points[i].Y);

                    currentFrame.DrawPolyline(hull.ToArray(), true, new Bgr(200, 125, 75), 2);
                    currentFrame.Draw(new CircleF(new PointF(box.center.X, box.center.Y), 3), new Bgr(200, 125, 75), 2);
                   // currentFrame.Draw(new CircleF(new PointF(handRect.center.X, handRect.center.Y), 3), new Bgr(200, 125, 75), 2);

                    //ellip.MCvBox2D= CvInvoke.cvFitEllipse2(biggestContour.Ptr);
                    //currentFrame.Draw(new Ellipse(ellip.MCvBox2D), new Bgr(Color.LavenderBlush), 3);

                   // PointF center;
                    // float radius;
                    //CvInvoke.cvMinEnclosingCircle(biggestContour.Ptr, out  center, out  radius);
                    //currentFrame.Draw(new CircleF(center, radius), new Bgr(Color.Gold), 2);

                    //currentFrame.Draw(new CircleF(new PointF(ellip.MCvBox2D.center.X, ellip.MCvBox2D.center.Y), 3), new Bgr(100, 25, 55), 2);
                    //currentFrame.Draw(ellip, new Bgr(Color.DeepPink), 2);

                    //CvInvoke.cvEllipse(currentFrame, new Point((int)ellip.MCvBox2D.center.X, (int)ellip.MCvBox2D.center.Y), new System.Drawing.Size((int)ellip.MCvBox2D.size.Width, (int)ellip.MCvBox2D.size.Height), ellip.MCvBox2D.angle, 0, 360, new MCvScalar(120, 233, 88), 1, Emgu.CV.CvEnum.LINE_TYPE.EIGHT_CONNECTED, 0);
                    //currentFrame.Draw(new Ellipse(new PointF(box.center.X, box.center.Y), new SizeF(box.size.Height, box.size.Width), box.angle), new Bgr(0, 0, 0), 2);

                    filteredHull = new Seq<Point>(storage);
                    for (int i = 0; i < hull.Total; i++)
                    {
                        if (Math.Sqrt(Math.Pow(hull[i].X - hull[i + 1].X, 2) + Math.Pow(hull[i].Y - hull[i + 1].Y, 2)) > box.size.Width / 10)
                        {
                            filteredHull.Push(hull[i]);
                        }
                    }

                    defects = biggestContour.GetConvexityDefacts(storage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);

                    defectArray = defects.ToArray();
                }
                            MCvMoments moment = new MCvMoments();               // a new MCvMoments object

            try
            {
                moment = biggestContour.GetMoments();           // Moments of biggestContour
            }
            catch (NullReferenceException)
            {

            }
            int fingerNum = 0;
            CvInvoke.cvMoments(biggestContour, ref moment, 0);

            double m_00 = CvInvoke.cvGetSpatialMoment(ref moment, 0, 0);
            double m_10 = CvInvoke.cvGetSpatialMoment(ref moment, 1, 0);
            double m_01 = CvInvoke.cvGetSpatialMoment(ref moment, 0, 1);

            int current_X = Convert.ToInt32(m_10 / m_00) / 10;      // X location of centre of contour
            int current_Y = Convert.ToInt32(m_01 / m_00) / 10;      // Y location of center of contour

             if (fingerNum == 1 || fingerNum == 0 || blue == 6)
             {
                 Cursor.Position = new Point(current_X * 10, current_Y * 10);
             }
             //Leave the cursor where it was and Do mouse click, if finger count >= 3

                }
        }
开发者ID:nikhilemmanuel,项目名称:Gesturised_Computer_Operation,代码行数:100,代码来源:Form1.cs

示例11: testPolygonTest

        public void testPolygonTest()
        {
            // CvArray<float> m = new CvArray<float>(); // = new CvArray<float>;
            //Matrix<PointF> m = new Matrix<PointF>(1,3);
            //m[0,0] = new PointF(.0f, .0f);
            //m[0,1] = new PointF(1.0f, .0f);
            //m[0,2] = new PointF(.0f, 1.0f);
            // Matrix<float> m = new Matrix<float>(3, 2);
            //float[] m = new float[6];
            //m[0] = .0f; m[1] = .0f;
            //m[2] = 1.0f; m[3] = .0f;
            //m[4] = .0f; m[5] = 1.0f;
            //List<PointF> m = new List<PointF>(3);
            //m[0] = new PointF(.0f, .0f);
            //m[0] = new PointF(1.0f, .0f);
            //m[0] = new PointF(.0f, 1.0f);
            // IntPtr m = CvInvoke.cvCreateMat(3,2,Emgu.CV.CvEnum.MAT_DEPTH.CV_32F);
            //CvInvoke.cvSet2D(m, 0, 0, (Emgu.CV.Structure.MCvScalar).0f);
            //CvInvoke.cvSet2D(m, 0, 1, .0f);
            //CvInvoke.cvSet2D(m, 0, 0, .0f);
            //unsafe
            //{
            //    float* p = (float*)m.ToPointer();
            //    p[0] = .0f; p[1] = .0f;
            //    p[2] = 1.0f; p[3] = .0f;
            //    p[4] = .0f; p[5] = 1.0f;
            //}
            //PointF[] m = new PointF[3];
            //m[0] = new PointF(.0f, .0f);
            //m[1] = new PointF(1.0f, .0f);
            //m[2] = new PointF(.0f, 1.0f);

            // Matrix<PointF> m = new Matrix<PointF>(3,1);
            //Matrix<float> m = new Matrix<float>(3, 2, 2);
            //m[0, 0] = .0f; m[0, 1] = .0f;
            //m[1, 0] = 1.0f; m[1, 1] = .0f;
            //m[2, 0] = .0f; m[2, 1] = 1.0f;
            //PointF p0 = new PointF(.0f, .0f);
            //PointF p1 = new PointF(1.0f, .0f);
            //PointF p2 = new PointF(.0f, 1.0f);
            //PointF[] m = new PointF[3];
            //m[0] = p0;
            //m[1] = p1;
            //m[2] = p2;
            //Matrix<PointF> m = new Matrix<PointF>(3, 1, 4);
            //Matrix<PointF> m = new Matrix<PointF>(3, 1);
            //m[0, 0] = new PointF(.0f, .0f);
            //m[1, 0] = new PointF(1.0f, .0f);
            //m[2, 0] = new PointF(.0f, 1.0f);
            //Contour<PointF> m = new Contour<PointF>(storage);
            //Contour<PointF> m = new Contour<PointF>(storage);
            Seq<PointF> m = new Seq<PointF>(storage);
            m.Push(new PointF(.0f, .0f));
            m.Push(new PointF(1.0f, .0f));
            m.Push(new PointF(.0f, 1.0f));

            //double asd = CvInvoke.cvPointPolygonTest(Marshal.UnsafeAddrOfPinnedArrayElement(m, 0), new PointF(.2f, .3f), false);
            double asd = CvInvoke.cvPointPolygonTest((IntPtr)(m), new PointF(.2f, .3f), false);
        }
开发者ID:rijkaard,项目名称:EmguWorkbench,代码行数:59,代码来源:EmguController.cs

示例12: TestSnake

        public void TestSnake()
        {
            Image<Gray, Byte> img = new Image<Gray, Byte>(100, 100, new Gray());

             Rectangle rect = new Rectangle(40, 30, 20, 40);
             img.Draw(rect, new Gray(255.0), -1);

             using (MemStorage stor = new MemStorage())
             {
            Seq<Point> pts = new Seq<Point>((int)CvEnum.SEQ_TYPE.CV_SEQ_POLYGON, stor);
            pts.Push(new Point(20, 20));
            pts.Push(new Point(20, 80));
            pts.Push(new Point(80, 80));
            pts.Push(new Point(80, 20));

            Image<Gray, Byte> canny = img.Canny(new Gray(100.0), new Gray(40.0));
            Seq<Point> snake = canny.Snake(pts, 1.0f, 1.0f, 1.0f, new Size(21, 21), new MCvTermCriteria(40, 0.0002), stor);

            img.Draw(pts, new Gray(120), 1);
            img.Draw(snake, new Gray(80), 2);
             }
        }
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:22,代码来源:AutoTestImage.cs

示例13: ExtractFeatures

        public static FeatureVector ExtractFeatures(Image<Gray, byte> skin, Image<Bgr, Byte> imagen)
        {
            Contour<Point> currentContour = null;
            Contour<Point> biggestContour = null;

            using (MemStorage storage = new MemStorage())
            {

            #region extractContourAndHull
                Contour<Point> contours = skin.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage);

                Double Result1 = 0;
                Double Result2 = 0;
                while (contours != null)
                {
                    Result1 = contours.Area;
                    if (Result1 > Result2)
                    {
                        Result2 = Result1;
                        biggestContour = contours;
                    }
                    contours = contours.HNext;
                }

                if (biggestContour != null)
                {
                    currentContour = biggestContour.ApproxPoly(biggestContour.Perimeter * 0.0025, storage);
                    imagen.Draw(currentContour, new Bgr(Color.LimeGreen), 2);
                    biggestContour = currentContour;

                    hull = biggestContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                    box = biggestContour.GetMinAreaRect();
                    PointF[] points = box.GetVertices();

                    Point[] ps = new Point[points.Length];
                    for (int i = 0; i < points.Length; i++)
                        ps[i] = new Point((int)points[i].X, (int)points[i].Y);

                    imagen.DrawPolyline(hull.ToArray(), true, new Bgr(200, 125, 75), 2);
                    // imagen.Draw(new CircleF(new PointF(box.center.X, box.center.Y), 3), new Bgr(200, 125, 75), 2);

                    //  PointF center;
                    // float radius;

                    filteredHull = new Seq<Point>(storage);
                    for (int i = 0; i < hull.Total; i++)
                    {
                        if (Math.Sqrt(Math.Pow(hull[i].X - hull[i + 1].X, 2) + Math.Pow(hull[i].Y - hull[i + 1].Y, 2)) > box.size.Width / 10)
                        {
                            filteredHull.Push(hull[i]);
                        }
                    }

                    defects = biggestContour.GetConvexityDefacts(storage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);

                    defectArray = defects.ToArray();
                }
            }

                #endregion

            #region find palm center(needs change)

               searchRadius = 6;
               contourReduction = 3;

            //this.result = null;

            DetectarCentroPalma(biggestContour.ToList<Point>(), obtenerListaCandidatos(box));

            PointF punto = new PointF(405, 380);
            Point punt = new Point(405, 380);
            CircleF centerCircle = new CircleF(punto, 5f);
            //CircleF centerCircle = new CircleF(result.Location, 5f);
            imagen.Draw(centerCircle, new Bgr(Color.Brown), 3);

            /*
             for (int i = 0; i < defects.Total; i++)
             {
                 LineSegment2D lineaDedoCentro = new LineSegment2D(defectArray[i].StartPoint, punt);
                 imagen.Draw(lineaDedoCentro, new Bgr(Color.Green), 2);

             }
             * */

            #endregion

            List<PointF> fingertips = defectsDrawing(imagen, ref punt);

            #region create feature vector
            List<PointF> newFingertips = ordenarFingertips(fingertips);
            List<float> angles = calculateFingerAngles(fingertips, punto);

            FeatureVector vector = new FeatureVector(newFingertips, angles, punto, 5);
            //MessageBox.Show("Done");

               // frmPruebaDatos datos = new frmPruebaDatos(vector);
               // datos.Show();

            #endregion
//.........这里部分代码省略.........
开发者ID:SmartAlexa,项目名称:iterative-map-estimation,代码行数:101,代码来源:ObservedImageFunctions.cs

示例14: ExtractContourAndHull

        private void ExtractContourAndHull(Image<Gray, byte> skin, Image<Bgr,byte> currentFrame)
        {
            using (MemStorage storage = new MemStorage())
            {
                Contour<System.Drawing.Point> contours = skin.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage);
                Contour<System.Drawing.Point> biggestContour = null;

                Double Result1 = 0;
                Double Result2 = 0;
                while (contours != null)
                {
                    Result1 = contours.Area;
                    if (Result1 > Result2)
                    {
                        Result2 = Result1;
                        biggestContour = contours;
                    }
                    contours = contours.HNext;
                }

                if (biggestContour != null)
                {
                    currentFrame.Draw(biggestContour, new Bgr(Color.DarkViolet), 2);
                    Contour<System.Drawing.Point> currentContour = biggestContour.ApproxPoly(biggestContour.Perimeter * 0.0025, storage);
                    currentFrame.Draw(currentContour, new Bgr(System.Drawing.Color.LimeGreen), 2);
                    biggestContour = currentContour;


                    hull = biggestContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);
                    box = biggestContour.GetMinAreaRect();
                    PointF[] points = box.GetVertices();
                    //handRect = box.MinAreaRect();
                    //currentFrame.Draw(handRect, new Bgr(200, 0, 0), 1);

                    System.Drawing.Point[] ps = new System.Drawing.Point[points.Length];
                    for (int i = 0; i < points.Length; i++)
                        ps[i] = new System.Drawing.Point((int)points[i].X, (int)points[i].Y);

                    currentFrame.DrawPolyline(hull.ToArray(), true, new Bgr(200, 125, 75), 2);
                    currentFrame.Draw(new CircleF(new PointF(box.center.X, box.center.Y), 3), new Bgr(200, 125, 75), 2);


                    filteredHull = new Seq<System.Drawing.Point>(storage);
                    for (int i = 0; i < hull.Total; i++)
                    {
                        if (Math.Sqrt(Math.Pow(hull[i].X - hull[i + 1].X, 2) + Math.Pow(hull[i].Y - hull[i + 1].Y, 2)) > box.size.Width / 10)
                        {
                            filteredHull.Push(hull[i]);
                        }
                    }

                    
                    defects = biggestContour.GetConvexityDefacts(storage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);

                    defectArray = defects.ToArray();
                    DrawAndComputeFingersNum(currentFrame,filteredHull,defects,defectArray);
                }
                

                imageConvexHull.Source = toBitmapSourceFromImage(currentFrame);
            }
        }
开发者ID:GitRoberta,项目名称:kinectRecognitionHand,代码行数:62,代码来源:MainWindow.xaml.cs


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