Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between BFMatcher and FlannBasedMatcher

Tags:

I would like to know what is the difference in term of precision or quality of the matches between the BFMatcher and FlannBasedMatcher in openCV. I know the FlannBasedMatcher might be faster when applied to a large data base but are the two matcher going to find the same matches at the end regardless of the time of execution?

like image 548
Tulkkas Avatar asked May 16 '12 01:05

Tulkkas


People also ask

What is FlannBasedMatcher?

FLANN based Matcher FLANN stands for Fast Library for Approximate Nearest Neighbors. It contains a collection of algorithms optimized for fast nearest neighbor search in large datasets and for high dimensional features. It works faster than BFMatcher for large datasets.

What is BFMatcher?

Brute-Force matcher is simple. It takes the descriptor of one feature in first set and is matched with all other features in second set using some distance calculation. And the closest one is returned. For BF matcher, first we have to create the BFMatcher object using cv. BFMatcher().

How does BFMatcher work?

Brute Force Matcher is used for matching the features of the first image with another image. It takes one descriptor of first image and matches to all the descriptors of the second image and then it goes to the second descriptor of first image and matches to all the descriptor of the second image and so on.

How does FLANN matcher work?

FLANN (Fast Library for Approximate Nearest Neighbors) is an image matching algorithm for fast approximate nearest neighbor searches in high dimensional spaces. These methods project the high-dimensional features to a lower-dimensional space and then generate the compact binary codes.


2 Answers

BFMatcher is going to try all the possibilities (which is the meaning of "Brute Force" and hence it will find the best matches.

FLANN, meaning "Fast Library for Approximate Nearest Neighbors", will be much faster but will find an approximate nearest neighbors. It will find a good matching, but not necessarily the best possible one. You can play with FLANN's parameters in order to increase the precision (i.e. the "quality" of the matchings), but it will be at the cost of slowing the algorithm.

In other words: FLANN is much faster than BFMatcher but it only finds an approximate nearest neighbor, which is a good matching but not necessarily the best. You can play with the parameters of FLANN in order to increase its speed or its precision.

like image 137
JonasVautherin Avatar answered Sep 24 '22 03:09

JonasVautherin


To add to the above answer, FLANN builds an efficient data structure (KD-Tree) that will be used to search for an approximate neighbour, while cv::BFMatcher does an exhaustive search and is guaranteed to find the best neighbour. The real benefit of FLANN is seen with large data sets. In my experience, I've seen a justifiable benefit is the number of descriptors is larger than 1K.

like image 44
gitfredy Avatar answered Sep 22 '22 03:09

gitfredy