问题
I am running Ubuntu 14.04. I am trying to run FLANN with openCV 3 but I get an error.
Everything bellow was tried by using AKAZE and ORB but the code if from my attempt to use ORB.
I use ORB to find the descriptors and key-points.
Ptr<ORB> detector = ORB::create();
std::vector<KeyPoint> keypoints_1, keypoints_2;
Mat descriptors_1, descriptors_2;
detector->detectAndCompute( img_1, noArray(), keypoints_1, descriptors_1 );
detector->detectAndCompute( img_2, noArray(), keypoints_2, descriptors_2 );
After I use ORB, I use the following code to find matches:
FlannBasedMatcher matcher;
std::vector<DMatch> matches;
matcher.match(descriptors_1, descriptors_2, matches);
The code builds fine and everything. When I run the code I get this error:
OpenCV Error: Unsupported format or combination of formats (type=0
) in buildIndex_, file /home/jim/opencv/modules/flann/src/miniflann.cpp, line 315
terminate called after throwing an instance of 'cv::Exception'
what(): /home/jim/opencv/modules/flann/src/miniflann.cpp:315: error: (-210) type=0
in function buildIndex_
Aborted (core dumped)
Can anybody tell me why? Is it something with OpenCV 3 being in BETA state? Is there an alternative to FLANN (except BFMatcher)
回答1:
So what I said:
in order to use FlannBasedMatcher
you need to convert your descriptors to CV_32F
:
if(descriptors_1.type()!=CV_32F) {
descriptors_1.convertTo(descriptors_1, CV_32F);
}
if(descriptors_2.type()!=CV_32F) {
descriptors_2.convertTo(descriptors_2, CV_32F);
}
you can take a look to this similar question:
回答2:
The answer by Rafael Ruiz Muñoz is wrong.
Convert the descriptors to CV_32F elimilated the assertion error. But, the matcher will behavior in the wrong way.
ORB is hamming descriptor. By default, the FlannBasedMatcher creates L2 euclid KDTreeIndexParams().
Try to init the matcher in the flowing way,
cv::FlannBasedMatcher matcher(new cv::flann::LshIndexParams(20, 10, 2));
回答3:
Unsupported format or combination of formats
is also thrown if no descriptors could be computed.
You can check if that's the case using empty()
after detectAndCompute
, thus:
detector->detectAndCompute( img_1, noArray(), keypoints_1, descriptors_1 );
detector->detectAndCompute( img_2, noArray(), keypoints_2, descriptors_2 );
if ( descriptors_1.empty() ) {
cvError(0,"MatchFinder","descriptors_1 descriptor empty",__FILE__,__LINE__);
}
if ( descriptors_2.empty() ) {
cvError(0,"MatchFinder","descriptors_2 empty",__FILE__,__LINE__);
}
来源:https://stackoverflow.com/questions/29694490/flann-error-in-opencv-3