private void MatchBySift(Mat src1, Mat src2) { var gray1 = new Mat(); var gray2 = new Mat(); Cv2.CvtColor(src1, gray1, ColorConversion.BgrToGray); Cv2.CvtColor(src2, gray2, ColorConversion.BgrToGray); var sift = new SIFT(); // Detect the keypoints and generate their descriptors using SIFT KeyPoint[] keypoints1, keypoints2; var descriptors1 = new MatOfFloat(); var descriptors2 = new MatOfFloat(); sift.Run(gray1, null, out keypoints1, descriptors1); sift.Run(gray2, null, out keypoints2, descriptors2); // Match descriptor vectors var bfMatcher = new BFMatcher(NormType.L2, false); var flannMatcher = new FlannBasedMatcher(); DMatch[] bfMatches = bfMatcher.Match(descriptors1, descriptors2); DMatch[] flannMatches = flannMatcher.Match(descriptors1, descriptors2); // Draw matches var bfView = new Mat(); Cv2.DrawMatches(gray1, keypoints1, gray2, keypoints2, bfMatches, bfView); var flannView = new Mat(); Cv2.DrawMatches(gray1, keypoints1, gray2, keypoints2, flannMatches, flannView); using (new Window("SIFT matching (by BFMather)", WindowMode.AutoSize, bfView)) using (new Window("SIFT matching (by FlannBasedMatcher)", WindowMode.AutoSize, flannView)) { Cv2.WaitKey(); } }
private void MatchBySift(Mat src1, Mat src2) { Mat gray1 = new Mat(); Mat gray2 = new Mat(); Cv2.CvtColor(src1, gray1, ColorConversion.BgrToGray); Cv2.CvtColor(src2, gray2, ColorConversion.BgrToGray); SIFT sift = new SIFT(); // Detect the keypoints and generate their descriptors using SIFT KeyPoint[] keypoints1, keypoints2; MatOfFloat descriptors1 = new MatOfFloat(); MatOfFloat descriptors2 = new MatOfFloat(); sift.Run(gray1, null, out keypoints1, descriptors1); sift.Run(gray2, null, out keypoints2, descriptors2); // Matching descriptor vectors with a brute force matcher BFMatcher matcher = new BFMatcher(NormType.L2, false); DMatch[] matches = matcher.Match(descriptors1, descriptors2); // Draw matches Mat view = new Mat(); Cv2.DrawMatches(gray1, keypoints1, gray2, keypoints2, matches, view); using (new Window("SIFT matching", WindowMode.AutoSize, view)) { Cv2.WaitKey(); } }
public void GetData() { var imPath = "D:\\PATHTOIMAGE\\Original.jpg"; var image = Cv2.ImRead(imPath); var sift = new SIFT(100); KeyPoint[] keypoints; MatOfFloat descriptors = new MatOfFloat(); sift.Run(image, null, out keypoints, descriptors); }
private static void Run() { var dm = DescriptorMatcher.Create("BruteForce"); dm.Clear(); string[] algoNames = Algorithm.GetList(); Console.WriteLine(String.Join("\n", algoNames)); SIFT al1 = new SIFT(); string[] ppp = al1.GetParams(); Console.WriteLine(ppp); var t = al1.ParamType("contrastThreshold"); double d = al1.GetDouble("contrastThreshold"); t.ToString(); d.ToString(); var src = new Mat("data/lenna.png"); var rand = new Random(); var memory = new List<long>(100); var a1 = new Mat(src, Rect.FromLTRB(0, 0, 30, 40)); var a2 = new Mat(src, Rect.FromLTRB(0, 0, 30, 40)); var a3 = new Mat(src, Rect.FromLTRB(0, 0, 30, 40)); a3.ToString(); for (long i = 0; ; i++) { for (int j = 0; j < 200; j++) { int c1 = rand.Next(100, 400); int c2 = rand.Next(100, 400); Mat temp = src.Row[c1]; src.Row[c1] = src.Row[c2]; src.Row[c2] = temp; } memory.Add(MyProcess.WorkingSet64); if (memory.Count >= 100) { double average = memory.Average(); Console.WriteLine("{0:F3}MB", average / 1024.0 / 1024.0); memory.Clear(); GC.Collect(); } } }