Fast matching of binary descriptors using flann

Viewed 837

I want to match a set of binary descriptors (query data) against a larger set of binary descriptors (train data).

The matching should be done fast. I decided to try the FlannBasedMatcher of OpenCv. The matcher supports a variety of Algorithms. For binary descriptors there is Multi-Probe LSH implemented.

FlannBasedMatcher matcher (new flann::LshIndexParams(12,10,2));
std::vector<DMatch> matches;
matcher.knnMatch(query, train, matches, 2);

(I tried different LshIndexParams settings)

The Problem is that Flann matching with LSH is very slow compared to BruteForce Matching or compared to Flann matching with KDTreeIndexParams using float descriptors.

It also looks like some others experienced the same problem (see 1, 2). In one of the answers it is suggested to try Hierarchical Clustering. That should be faster than LSH.

I would like to use the same FlannBasedMatcher Interface as with LSH.

FlannBasedMatcher matcher (new flann::HierarchicalClusteringIndexParams());
std::vector<DMatch> matches;
matcher.knnMatch(query, train, matches, 2);

However this doesn't work with binary descriptors (see the error message):

OpenCV Error: Unsupported format or combination of formats 

But the "raw" Hierarchical Clustering interface supports multiple distance types and it is possible to choose the hamming distance.

cv::flann::Index tree(train, cv::flann::HierarchicalClusteringIndexParams(), FLANN_DIST_HAMMIN‌​G); 
cv::Mat indices, dists; 
tree.knnSearch(query, indices, dists, 2, cv::flann::SearchParams());

My questions are:

  • Is it possible to set a distance type for the FlannBasedMatcher to work with binary descriptors and with Hierarchical Clustering? Or can I define a custom flann::HierarchicalClusteringIndexParams() with Hamming distance? I would like to use the FlannBasedMatcher interface.
  • Is there an alternative faster method for matching binary descriptors? Better/faster than using FLANN with LSH or Hierarchical Clustering?
0 Answers
Related