Пример #1
0
 private void calculatedescriptors(Mat image, UMat imageDescriptors, VectorOfKeyPoint imageKeyPoints)
 {
     using (UMat mImage = image.ToUMat(Emgu.CV.CvEnum.AccessType.Read))
     {
         SIFT sift = new SIFT();
         sift.DetectAndCompute(mImage, null, imageKeyPoints, imageDescriptors, false);
     }
 }
Пример #2
0
        public static int SiftComparison(string img1, string img2)
        {
            var sift = new Emgu.CV.XFeatures2D.SIFT();

            var modelKeyPoints   = new VectorOfKeyPoint();
            Mat modelDescriptors = new Mat();

            var observedKeyPoints   = new VectorOfKeyPoint();
            Mat observedDescriptors = new Mat();
            Mat mask = new Mat();

            VectorOfVectorOfDMatch matches = new VectorOfVectorOfDMatch();
            int    k = 2;
            double uniquenessThreshold = 0.80;

            using (Mat modelImage = CvInvoke.Imread(img1, ImreadModes.Grayscale))
                using (Mat observedImage = CvInvoke.Imread(img2, ImreadModes.Grayscale))
                {
                    sift.DetectAndCompute(modelImage, null, modelKeyPoints, modelDescriptors, false);
                    sift.DetectAndCompute(observedImage, null, observedKeyPoints, observedDescriptors, false);
                    BFMatcher matcher = new BFMatcher(DistanceType.L1);

                    matcher.Add(modelDescriptors);
                    //matcher.Add(observedDescriptors);

                    matcher.KnnMatch(observedDescriptors, matches, k, null);
                    mask = new Mat(matches.Size, 1, DepthType.Cv8U, 1);
                    mask.SetTo(new MCvScalar(255));
                    try
                    {
                        Features2DToolbox.VoteForUniqueness(matches, uniquenessThreshold, mask);
                    }
                    catch (Exception ex)
                    {
                        Log(ex.Message);
                        Log("Error with SIFT algorithm, unable to compare images..");
                        return(0);
                    }
                }

            int score = 0;

            for (int i = 0; i < matches.Size; i++)
            {
                if (mask.GetData(i)[0] == 0)
                {
                    continue;
                }
                foreach (var e in matches[i].ToArray())
                {
                    ++score;
                }
            }

            return(score);
        }
Пример #3
0
 public void TestSIFT()
 {
    SIFT detector = new SIFT();
    EmguAssert.IsTrue(TestFeature2DTracker(detector, detector), "Unable to find homography matrix");
 }
Пример #4
0
 public void TestMSER()
 {
    MSERDetector keyPointDetector = new MSERDetector();
    SIFT descriptorGenerator = new SIFT();
    //ParamDef[] parameters = keyPointDetector.GetParams();
    TestFeature2DTracker(keyPointDetector, descriptorGenerator);
 }
Пример #5
0
 public void TestGFTTDetector()
 {
    GFTTDetector keyPointDetector = new GFTTDetector(1000, 0.01, 1, 3, false, 0.04);
    SIFT descriptorGenerator = new SIFT();
    //ParamDef[] parameters = keyPointDetector.GetParams();
    TestFeature2DTracker(keyPointDetector, descriptorGenerator);
 }
Пример #6
0
      public void TestStar()
      {
         StarDetector keyPointDetector = new StarDetector();

         //SURF descriptorGenerator = new SURF(500, false);
         SIFT descriptorGenerator = new SIFT();
         //ParamDef[] parameters = keyPointDetector.GetParams();
         TestFeature2DTracker(keyPointDetector, descriptorGenerator);
      }