I'm developing a program to detect similarities between two pictures, in order to determine if they represent the same object. After studying the subject, I've determined that 3 main components are needed:
I've successfully implemented the first two (PM me if you need help with it, I know it can be a huge pain), but I'm having problems with the matcher. Here's a part of the code I use:
DMatch matches = new DMatch();
BFMatcher matcher = new BFMatcher(NORM_HAMMING, true);
[...]
matcher.match(descriptor1, descriptor2, matches, null);
System.out.println("Matches: " + matches.capacity());
The output of matches.capacity() is 58, when I was hoping it would be the exact same number of keypoints or descriptor points (because I'm comparing an image to itself...). Am I expecting the wrong result? Am I doing something else wrong? Some help would be greatly appreciated :)
EDIT:
I've managed to finish my program, and can now answer to my own question, hoping it will help someone in my previous situation:
The matcher.match(...) method computes the binary strings or float vectors that describe each image (e.g. descriptor1 and descriptor2), returning the query index (index of the keypoint in keypoints1), the train index (the index of keypoints2 equivalent match for the point in queryIndex) and the hamming distance between those points. This matches every point in image 1 to every point in image 2 (at least from drawMatches, that's my conclusion), but if you want to determine a matching rate between two images, you need to filter the DMatch matches content. For this, you must create an algorithm yourself (none of the ones I found online worked well, e.g. 2*minDist).
If you need more help or some code, don't hesitate to PM me. I know how frustrating it can be to understand this whole image matching process!
You should use matches.size()
to obtain the effective number of matches found (capacity
gives the internal array allocated size).