コード例 #1
0
 /// <summary>
 /// Draw the keypoints found on the image.
 /// </summary>
 /// <param name="image">The image</param>
 /// <param name="keypoints">The keypoints to be drawn</param>
 /// <param name="color">The color used to draw the keypoints</param>
 /// <param name="type">The drawing type</param>
 /// <param name="outImage">The image with the keypoints drawn</param> 
 public static void DrawKeypoints(
    IInputArray image,
    VectorOfKeyPoint keypoints,
    IInputOutputArray outImage,
    Bgr color,
    Features2DToolbox.KeypointDrawType type)
 {
    MCvScalar c = color.MCvScalar;
    using (InputArray iaImage = image.GetInputArray())
    using (InputOutputArray ioaOutImage = outImage.GetInputOutputArray())
    CvInvoke.drawKeypoints(iaImage, keypoints, ioaOutImage, ref c, type);
 }
コード例 #2
0
        /// <summary>
        /// Detect the if the model features exist in the observed features. If true, an homography matrix is returned, otherwise, null is returned.
        /// </summary>
        /// <param name="modelDescriptors">The descriptors from the model image</param>
        /// <param name="modelKeyPoints">The keypoints drom the model image</param>
        /// <param name="observedDescriptors">The descriptors from the descriptor image</param>
        /// <param name="observedKeyPoints">The keypoints from the observed image</param>
        /// <param name="uniquenessThreshold">The distance different ratio which a match is consider unique, a good number will be 0.8</param>
        /// <returns>If the model features exist in the observed features, an homography matrix is returned, otherwise, null is returned.</returns>
        public static HomographyMatrix Detect(
            VectorOfKeyPoint modelKeyPoints, Matrix <TDescriptor> modelDescriptors,
            VectorOfKeyPoint observedKeyPoints, Matrix <TDescriptor> observedDescriptors, double uniquenessThreshold)
        {
            int          k  = 2;
            DistanceType dt = typeof(TDescriptor) == typeof(Byte) ? DistanceType.Hamming : DistanceType.L2;

            using (Matrix <int> indices = new Matrix <int>(observedKeyPoints.Size, k))
                using (Matrix <float> dist = new Matrix <float>(indices.Size))
                    using (BruteForceMatcher <TDescriptor> matcher = new BruteForceMatcher <TDescriptor>(dt))
                        using (Matrix <byte> mask = new Matrix <byte>(dist.Rows, 1))
                        {
                            matcher.Add(modelDescriptors);
                            matcher.KnnMatch(observedDescriptors, indices, dist, k, null);

                            mask.SetValue(255);

                            //Stopwatch w1 = Stopwatch.StartNew();
                            Features2DToolbox.VoteForUniqueness(dist, uniquenessThreshold, mask);
                            //Trace.WriteLine(w1.ElapsedMilliseconds);

                            int nonZeroCount = CvInvoke.cvCountNonZero(mask);
                            if (nonZeroCount < 4)
                            {
                                return(null);
                            }

                            //Stopwatch w2 = Stopwatch.StartNew();
                            nonZeroCount = Features2DToolbox.VoteForSizeAndOrientation(modelKeyPoints, observedKeyPoints, indices, mask, 1.5, 20);
                            if (nonZeroCount < 4)
                            {
                                return(null);
                            }

                            return(Features2DToolbox.GetHomographyMatrixFromMatchedFeatures(modelKeyPoints, observedKeyPoints, indices, mask, 3));
                        }
        }