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


C# Contour.InContour方法代码示例

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


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

示例1: CamShiftTrack

      /// <summary>
      /// Use camshift to track the feature
      /// </summary>
      /// <param name="observedFeatures">The feature found from the observed image</param>
      /// <param name="initRegion">The predicted location of the model in the observed image. If not known, use MCvBox2D.Empty as default</param>
      /// <param name="priorMask">The mask that should be the same size as the observed image. Contains a priori value of the probability a match can be found. If you are not sure, pass an image fills with 1.0s</param>
      /// <returns>If a match is found, the homography projection matrix is returned. Otherwise null is returned</returns>
      public HomographyMatrix CamShiftTrack(SURFFeature[] observedFeatures, MCvBox2D initRegion, Image<Gray, Single> priorMask)
      {
         using (Image<Gray, Single> matchMask = new Image<Gray, Single>(priorMask.Size))
         {
            #region get the list of matched point on the observed image
            Single[, ,] matchMaskData = matchMask.Data;

            //Compute the matched features
            MatchedSURFFeature[] matchedFeature = _matcher.MatchFeature(observedFeatures, 2, 20);
            matchedFeature = VoteForUniqueness(matchedFeature, 0.8);

            foreach (MatchedSURFFeature f in matchedFeature)
            {
               PointF p = f.ObservedFeature.Point.pt;
               matchMaskData[(int)p.Y, (int)p.X, 0] = 1.0f / (float) f.SimilarFeatures[0].Distance;
            }
            #endregion

            Rectangle startRegion;
            if (initRegion.Equals(MCvBox2D.Empty))
               startRegion = matchMask.ROI;
            else
            {
               startRegion = PointCollection.BoundingRectangle(initRegion.GetVertices());
               if (startRegion.IntersectsWith(matchMask.ROI))
                  startRegion.Intersect(matchMask.ROI);
            }

            CvInvoke.cvMul(matchMask.Ptr, priorMask.Ptr, matchMask.Ptr, 1.0);

            MCvConnectedComp comp;
            MCvBox2D currentRegion;
            //Updates the current location
            CvInvoke.cvCamShift(matchMask.Ptr, startRegion, new MCvTermCriteria(10, 1.0e-8), out comp, out currentRegion);

            #region find the SURF features that belongs to the current Region
            MatchedSURFFeature[] featuesInCurrentRegion;
            using (MemStorage stor = new MemStorage())
            {
               Contour<System.Drawing.PointF> contour = new Contour<PointF>(stor);
               contour.PushMulti(currentRegion.GetVertices(), Emgu.CV.CvEnum.BACK_OR_FRONT.BACK);

               CvInvoke.cvBoundingRect(contour.Ptr, 1); //this is required before calling the InContour function

               featuesInCurrentRegion = Array.FindAll(matchedFeature,
                  delegate(MatchedSURFFeature f)
                  { return contour.InContour(f.ObservedFeature.Point.pt) >= 0; });
            }
            #endregion

            return GetHomographyMatrixFromMatchedFeatures(VoteForSizeAndOrientation(featuesInCurrentRegion, 1.5, 20 ));
         }
      }
开发者ID:Rustemt,项目名称:emgu_openCV,代码行数:60,代码来源:SURFTracker.cs

示例2: 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

示例3: plotPointValid

 private bool plotPointValid(Point p, Contour<Point> contour)
 {
     bool correctDistance;
     if (frame < 3)
         correctDistance = (getPointDistance(convertPoint3D(lastPoint), p) < 80);
     else
         correctDistance = (getPointDistance(this.lastPalmPoint, p) < 40);
     return (contour.InContour(p) > 0 && correctDistance);
 }
开发者ID:faddison,项目名称:KMouse,代码行数:9,代码来源:MainWindow.cs

示例4: getCandidatePoints

        /*
         * Draws three rings around the center point. Generates points on the circle by powers of 2.
         * ie. first ring has 4 points, second 8, third 16, etc..
         * try 2.3 for factor
         */
        private List<Point> getCandidatePoints(Graphics g, Contour<Point> contour, Point centerPoint, double initialRadius, double factor)
        {
            List<Point> candidatePoints = new List<Point>();
            candidatePoints.Add(centerPoint);
            double factoredRadius = initialRadius;

            for (int i = 0; i < 7; i++)
            {
                int numPoints = (int)Math.Pow(2, i + 2);
                double circumference = Math.PI * 2 * factoredRadius;
                double arcLength = circumference / numPoints;

                for (int j = 0; j < numPoints; j++)
                {
                    double radians = (j * arcLength) / factoredRadius;
                    double degrees = radians * (180 / Math.PI);
                    Point candidatePoint = getPointOnCircle(centerPoint, factoredRadius, radians);
                    if (contour.InContour(candidatePoint) > 0 &&
                        getPointDistance(convertPoint3D(lastPoint), candidatePoint) < 50)
                        candidatePoints.Add(candidatePoint);
                }
                //drawCircle(g, new Pen(Brushes.BlueViolet), centerPoint, (int) factoredRadius);
                //factoredRadius *= (int)factor;
                factoredRadius = initialRadius * (i + 1);
            }
            //Console.WriteLine("Candidate Points: {0}", candidatePoints.Count());
            return candidatePoints;
        }
开发者ID:faddison,项目名称:KMouse,代码行数:33,代码来源:MainWindow.cs


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