Question

I need to do similarity matching between two images. For that, I'm using ORB keypoints detector and ORB descriptor extractor from OpenCV in C++

My problem is in the matching. I decided to test two types of matching: FLANNBasedMatcher using LSH and BFMatcher. Where, according to documentation and both algorithms, LSH suppose to be faster than brute force (the first one doesn't compare all descriptors one by one and the second one does).

When I tried both, I got BFMatcher faster than LSH (But much faster), and I have no idea why and how to fix it.

At the beginning I though it needed more keypoints in order to see a difference, and I decided to increase this by letting ORB detect up to 70000 keypoints:

OrbFeatureDetector detector(70000);

But this made it even slower.

I don't know if my assumption of LSH being faster than brute force is wrong, or if I'm doing something wrong with my code.

My code:

//Detector
    int numKeyPoints = 70000; 
    OrbFeatureDetector detector(numKeyPoints); 
    detector.detect( image, keypoints); 

// Extractor
    OrbDescriptorExtractor extractor;
    extractor.compute(image, keypoints, descriptors); 

// BFMatcher
    BFMatcher matcher(NORM_HAMMING); 
    matcher.radiusMatch(descriptors_1, descriptors_2, matches, 30);


// LSHMatcher
    FlannBasedMatcher matcher(new flann::LshIndexParams(6,12,2));
    matcher.knnMatch(descriptors_1, descriptors_2, matches, 1); 

The average time:

  • Brute Force = 0.006 s per image
  • LSH = 0.04 s per image
Was it helpful?

Solution

Is it known bug. Try to use Hierarchical Clustering - it is much faster than bruteforce.

cv::flann::Index tree(Desriptors,cv::flann::HierarchicalClusteringIndexParams(),FLANN_DIST_HAMMIN‌​G); 
cv::Mat indices, dists; 
tree.knnSearch(Desriptors2, indices, dists, 1, cv::flann::SearchParams());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top