Ask Your Question

Using FLANN with binary descriptors (Brief,ORB)

asked 2012-07-19 15:01:20 -0500

yes123 gravatar image

updated 2012-07-19 15:29:34 -0500

I am trying to use FLANN with binary descriptors (brief, orb) with no luck. My code looks something like this:

vector<vector<KeyPoint> > dbKeypoints;
vector<Mat> dbDescriptors;
vector<Mat> objects;   

  load Descriptors from images (with OrbDescriptorExtractor())

FlannBasedMatcher matcher;

matcher.train()              //> Crash! (or any call to matcher.match())

If I use SurfDescriptorExtractor() it works well.

How can I solve this?

OpenCV says:

OpenCV Error: Unsupported format or combination of formats (type=0
) in unknown function, file D:\Value\Personal\Parthenope\OpenCV\modules\flann\sr
c\miniflann.cpp, line 299

(Note: i have posted the same question on stackoverflow)

I have found an hacky solution but i think it's not so good here

Basically the author before adding to FLANN converts the binary descriptors to CV_32F. But i don't think it's good beacuse distance must be calculated with HAMMING distance, and not euclian distance with float values.

edit retag flag offensive close merge delete



I don't think that the FLANN library can do well with Hamming distances. Locality-sensitive hashing may be more suitable for your case.

AngelLeliel gravatar imageAngelLeliel ( 2012-07-19 20:51:17 -0500 )edit

@angel: Yes I have tried LSH but the software crashes. Maria said there is a bug

yes123 gravatar imageyes123 ( 2012-07-20 04:25:43 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2012-07-20 02:58:17 -0500

Maria Dimashova gravatar image

By default FlannBasedMatcher works as KDTreeIndex with L2 norm. This is the reason why it works well with SURF descriptors and throws an exception for binary descriptors (that are matched by HAMMING distance) in your experiments. For the binary descriptors you should use flann::LshIndexParams. But there is some bug with it now, see my answer here

edit flag offensive delete link more

answered 2017-05-11 23:34:58 -0500

Sloan gravatar image

This question bothered a few days too. I found the answer from this site

You need to convert the format of your descriptor into CV_32F

if(descriptors_1.type()!=CV_32F) {
descriptors_1.convertTo(descriptors_1, CV_32F); }
edit flag offensive delete link more


Brilliant. It resolved the problem for me. Thank you!

hayley gravatar imagehayley ( 2018-07-13 09:00:35 -0500 )edit

I implemented the same work around, however FLANN matching takes longer than a brute-force comparison, which is not right.

gerardWalsh gravatar imagegerardWalsh ( 2018-08-10 04:00:39 -0500 )edit

Question Tools

1 follower


Asked: 2012-07-19 15:01:20 -0500

Seen: 11,997 times

Last updated: Jul 20 '12