Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

ORB Detector / ORB Extractor retrieve bad results

$
0
0
I'm trying to get similar results as in ![image description](http://docs.opencv.org/2.4/_images/Featur_FlannMatcher_Result.jpg) "http://docs.opencv.org/2.4/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.html#feature-flann-matcher" but I'm employing ORB rather than SURF and bruteforce instead of FLANN. Descriptors and matches I get seem almost random. ![image description](/upfiles/14635705625096181.bmp) My code is as follows package main; import java.util.ArrayList; import java.util.List; import org.opencv.features2d.*; import org.opencv.core.*; import org.opencv.imgcodecs.*; public class Main { public static void main(String[] args) { System.loadLibrary("opencv_java310"); Mat img1 = Imgcodecs.imread("D:\\Projects\\HelloOpenCV\\box.png", Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE); Mat img2 = Imgcodecs.imread("D:\\Projects\\HelloOpenCV\\box_in_scene.png", Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE); FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB); MatOfKeyPoint keypoints1 = new MatOfKeyPoint(); detector.detect(img1, keypoints1); FeatureDetector detector2 = FeatureDetector.create(FeatureDetector.ORB); MatOfKeyPoint keypoints2 = new MatOfKeyPoint(); detector2.detect(img2, keypoints2); DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB); Mat descriptors1 = new Mat(); extractor.compute(img1, keypoints1, descriptors1); DescriptorExtractor extractor2 = DescriptorExtractor.create(DescriptorExtractor.ORB); Mat descriptors2 = new Mat(); extractor2.compute(img2, keypoints2, descriptors2); DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE); MatOfDMatch matches = new MatOfDMatch(); matcher.match(descriptors1, descriptors2, matches); /**/ List matchesList = matches.toList(); double maxDistance = 0; double minDistance = 1000; int rowCount = matchesList.size(); for (int i = 0; i < rowCount; i++) { double dist = matchesList.get(i).distance; if (dist < minDistance) minDistance = dist; if (dist > maxDistance) maxDistance = dist; } List goodMatchesList = new ArrayList(); double upperBound = 1.6 * minDistance; for (int i = 0; i < rowCount; i++) { if (matchesList.get(i).distance <= upperBound) { goodMatchesList.add(matchesList.get(i)); } } MatOfDMatch goodMatches = new MatOfDMatch(); goodMatches.fromList(goodMatchesList); Mat img_matches = new Mat(); Features2d.drawMatches(img1, keypoints1, img2, keypoints2, goodMatches, img_matches); Imgcodecs.imwrite("D:\\Projects\\HelloOpenCV\\Test.bmp", img_matches); } } I feel I'm missing something trivial here. I tried AKAZE/AKAZE either, result was different but not better.

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>