Esempio n. 1
0
 /// <summary>
 /// Compute the shape distance between two shapes defined by its contours.
 /// </summary>
 /// <param name="contour1">Contour defining first shape</param>
 /// <param name="contour2">Contour defining second shape</param>
 /// <returns>The shape distance between two shapes defined by its contours.</returns>
 public static double ComputeDistance(Point contour1, Point contour2)
 {
     using (Emgu.CV.Util.VectorOfPoint c1 = new Emgu.CV.Util.VectorOfPoint(new Point[] { contour1 }))
         using (Emgu.CV.Util.VectorOfPoint c2 = new Emgu.CV.Util.VectorOfPoint(new Point[] { contour2 }))
         {
             return(CvInvoke.Norm(c1, c2));
         }
 }
Esempio n. 2
0
        /// <summary>
        /// Draw the model image and observed image, the matched features and homography projection.
        /// </summary>
        /// <param name="modelImage">The model image</param>
        /// <param name="observedImage">The observed image</param>
        /// <param name="matchTime">The output total time for computing the homography matrix.</param>
        /// <returns>The model image and observed image, the matched features and homography projection.</returns>
        public static Mat Draw(Mat modelImage, Mat observedImage, out long matchTime, out long score)
        {
            Mat homography;
            VectorOfKeyPoint modelKeyPoints;
            VectorOfKeyPoint observedKeyPoints;

            using (VectorOfVectorOfDMatch matches = new VectorOfVectorOfDMatch())
            {
                Mat mask;
                FindMatch(modelImage, observedImage, out matchTime, out modelKeyPoints, out observedKeyPoints, matches,
                          out mask, out homography, out score);

                //Draw the matched keypoints
                Mat result = new Mat();
                Features2DToolbox.DrawMatches(modelImage, modelKeyPoints, observedImage, observedKeyPoints,
                                              matches, result, new MCvScalar(255, 255, 255), new MCvScalar(255, 255, 255), mask);

                #region draw the projected region on the image

                if (homography != null)
                {
                    //draw a rectangle along the projected model
                    Rectangle rect = new Rectangle(Point.Empty, modelImage.Size);
                    PointF[]  pts  = new PointF[]
                    {
                        new PointF(rect.Left, rect.Bottom),
                        new PointF(rect.Right, rect.Bottom),
                        new PointF(rect.Right, rect.Top),
                        new PointF(rect.Left, rect.Top)
                    };
                    pts = CvInvoke.PerspectiveTransform(pts, homography);

#if NETFX_CORE
                    Point[] points = Extensions.ConvertAll <PointF, Point>(pts, Point.Round);
#else
                    Point[] points = Array.ConvertAll <PointF, Point>(pts, Point.Round);
#endif
                    using (VectorOfPoint vp = new VectorOfPoint(points))
                    {
                        CvInvoke.Polylines(result, vp, true, new MCvScalar(255, 0, 0, 255), 5);
                    }
                }
                #endregion

                return(result);
            }
        }
 /// <summary>
 /// Push a value into the standard vector
 /// </summary>
 /// <param name="value">The value to be pushed to the vector</param>
 public void Push(VectorOfPoint value)
 {
     VectorOfVectorOfPointPush(_ptr, value.Ptr);
 }
 public DebuggerProxy(VectorOfPoint v)
 {
     _v = v;
 }
 /// <summary>
 /// Push multiple values from the other vector into this vector
 /// </summary>
 /// <param name="other">The other vector, from which the values will be pushed to the current vector</param>
 public void Push(VectorOfPoint other)
 {
     VectorOfPointPushVector(_ptr, other);
 }