opencv FLANN with ORB descriptors?
Asked Answered
M

4

19

I am trying to use FLANN with ORB descriptors, but opencv crashes with this simple code:

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

/*
  load Descriptors from images (with OrbDescriptorExtractor())
*/

FlannBasedMatcher matcher;

matcher.add(dbDescriptors); 
matcher.train() //> Crash!

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
Moira answered 19/7, 2012 at 16:29 Comment(0)
M
7

It's a bug. It will be fixed soon.

http://answers.opencv.org/question/503/how-to-use-the-lshindexparams/

Moira answered 27/7, 2012 at 21:24 Comment(0)
W
34

Flann needs the descriptors to be of type CV_32F so you need to convert them! find_object/example/main.cpp:

if(dbDescriptors.type()!=CV_32F) {
    dbDescriptors.convertTo(dbDescriptors, CV_32F);
}

may work ;-)

Woothen answered 3/8, 2012 at 15:20 Comment(3)
If somebody reaches this question but uses the OpenCV for Java, it might be CvType.CV_32F instead of CV_32F. This is due the structure that the OpenCV project decided to do the migration of code from C/C++.Keeney
is FLANNMatcher<L2> will be faster than BFMatcher<NORM_HAMMING> if I convert descriptors?Tailing
I have opened another question to ask about an error obtained with this supposed fix.Anemic
M
7

It's a bug. It will be fixed soon.

http://answers.opencv.org/question/503/how-to-use-the-lshindexparams/

Moira answered 27/7, 2012 at 21:24 Comment(0)
F
7

When using ORB you should construct your matcher like so:

FlannBasedMatcher matcher(new cv::flann::LshIndexParams(5, 24, 2));

I've also seen this constructor suggested:

FlannBasedMatcher matcher(new flann::LshIndexParams(20,10,2));
Foliage answered 20/4, 2015 at 19:49 Comment(0)
A
5

Binary-string descriptors - ORB, BRIEF, BRISK, FREAK, AKAZE etc.

Floating-point descriptors - SIFT, SURF, GLOH etc.


Feature matching of binary descriptors can be efficiently done by comparing their Hamming distance as opposed to Euclidean distance used for floating-point descriptors.

For comparing binary descriptors in OpenCV, use FLANN + LSH index or Brute Force + Hamming distance.

http://answers.opencv.org/question/59996/flann-error-in-opencv-3/


By default FlannBasedMatcher works as KDTreeIndex with L2 norm. This is the reason why it works well with SIFT/SURF descriptors and throws an exception for ORB descriptor.

Binary features and Locality Sensitive Hashing (LSH)

Performance comparison between binary and floating-point descriptors

Atilt answered 24/10, 2018 at 13:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.