Answer the question
In order to leave comments, you need to log in
Compare two images using orb descriptors?
tell me, please, what is the problem. I find ORB descriptors of two pictures, and then I compare their distances. But my program is not working properly.
private static Mat countImage(String path) {
Mat img1 = Imgcodecs.imread(path, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
ORB orb = ORB.create();
MatOfKeyPoint keypoints = new MatOfKeyPoint();
Mat descriptors = new Mat();
orb.detectAndCompute(img1, new Mat(), keypoints, descriptors);
return descriptors;
}
private static void compareImages(String path1, String path2) {
System.out.println(path1 + "-" + path2);
Mat descriptors1 = countImage(path1);
Mat descriptors2 = countImage(path2);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
MatOfDMatch matches = new MatOfDMatch();
matcher.match(descriptors1, descriptors2, matches);
List<DMatch> matchesList = matches.toList();
Double max_dist = 0.0;
Double min_dist = 100.0;
for (DMatch dMatch : matchesList) {
Double dist = (double) dMatch.distance;
if (dist < min_dist)
min_dist = dist;
if (dist > max_dist)
max_dist = dist;
}
List<DMatch> good_matches = new ArrayList<>();
for (DMatch aMatchesList : matchesList) {
if (aMatchesList.distance <= (1.5 * min_dist))
good_matches.add(aMatchesList);
}
good_matches.forEach(System.out::println);
}
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
compareImages("C:\\image\\5.jpg", "C:\\image\\6.jpg");
}
}
DMatch [queryIdx=7, trainIdx=467, imgIdx=0, distance=64.0]
DMatch [queryIdx=9, trainIdx=281, imgIdx=0, distance=63.0]
DMatch [queryIdx=10, trainIdx=146, imgIdx=0, distance=64.0]
DMatch [queryIdx=21, trainIdx=487, imgIdx=0, distance=51.0]
DMatch [queryIdx=22, trainIdx=160, imgIdx=0, distance=55.0]
DMatch [queryIdx=24, trainIdx=114, imgIdx=0, distance=66.0]
DMatch [queryIdx=32, trainIdx=105, imgIdx=0, distance=64.0]
DMatch [queryIdx=33, trainIdx=348, imgIdx=0, distance=65.0]
DMatch [queryIdx=36, trainIdx=57, imgIdx=0, distance=66.0]
...]
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question