3
votes

Is there a way to get the hamming distance between two matched descriptors when using the flann matcher without manually calculating it? (i.e. looping through the descriptors matched, XORing each element, then counting).

I am matching descriptors computed by ORB like so:

FlannBasedMatcher flannMatcher;
flannMatcher.match(des1, des2, matches);

If I check the distance:

cout << matches.at(0).distance;

I get the NORM_L2 distance, however my application requires the hamming distance.

Context:

The reason I want to do this is that I am generating train descriptors from a training image set using ORB, finding matches using the brute force matcher, then filtering poor matches based on hamming distance.

I then want to use the flann matcher to match descriptors on a webcam stream to these train descriptors (and show which of the training images most closely matches the current frame), but since the flann matcher doesn't seem to give the hamming distance I'm stuck when it comes to filtering out poor matches, and I get a lot of error when choosing the train image that matches best.

2

2 Answers

1
votes

In OpenCV's tutorial, it is described how to create flann based matcher for SIFT and ORB (here is the ORB)

While using ORB, you can pass the following. The commented values are recommended as per the docs, but it didn't provide required results in some cases. Other values worked fine.:

FLANN_INDEX_LSH = 6
index_params= dict(algorithm = FLANN_INDEX_LSH,
               table_number = 6, # 12
               key_size = 12,     # 20
               multi_probe_level = 1) #2

https://docs.opencv.org/3.4/dc/dc3/tutorial_py_matcher.html

0
votes

Try using flann::LshIndexParams as the distance type. This does Locality Sensitive Hashing (which is close to the Hamming distance)

FlannBasedMatcher matcher2(new flann::LshIndexParams(20,10,2));

See also the discussion here