Ask Your Question
0

Unsupported format or combination of formats in buildIndex using FLANN algorithm

asked 2013-04-10 04:51:00 -0600

matteo gravatar image

I'm acquiring some images from a video stream (of a simulated camera) : my goal is to find matching points in order to compute the Affine Transformation Matrix between two frames afterwards. I'm trying to use the Feature Matching with FLANN algorithm proposed by OpenCV (http://docs.opencv.org/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.html#feature-matching-with-flann) with 2 Mat type images acquired through the cv_bridge (http://www.ros.org/wiki/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages) since i read them from a ROS topic. this is my code:

 vector< DMatch > MatchFinder(Mat img_1, Mat img_2)
 {
int minHessian = 400;
unsigned int i;

SurfFeatureDetector detector( minHessian );

std::vector<KeyPoint> keypoints_1, keypoints_2;

detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );

//-- Step 2: Calculate descriptors (feature vectors)

SurfDescriptorExtractor extractor;

Mat descriptors_1, descriptors_2;

extractor.compute( img_1, keypoints_1, descriptors_1 );
extractor.compute( img_2, keypoints_2, descriptors_2 );

//-- Step 3: Matching descriptor vectors using FLANN matcher

FlannBasedMatcher matcher;

std::vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );  // ERROR

double max_dist = 0; double min_dist = 100;

//-- Quick calculation of max and min distances between keypoints
for( i = 0; i < descriptors_1.rows; i++ )
{ double dist = matches[i].distance;
if( dist < min_dist ) min_dist = dist;
if( dist > max_dist ) max_dist = dist;
}

printf("-- Max dist : %f \n", max_dist );
printf("-- Min dist : %f \n", min_dist );

//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist )
//-- PS.- radiusMatch can also be used here.
std::vector< DMatch > good_matches;

for(  i = 0; i < descriptors_1.rows; i++ )
{
  if( matches[i].distance < 2*min_dist )
{
      good_matches.push_back( matches[i]);
 }
 }

 //-- Draw only "good" matches
Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2,
           good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
           vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

//-- Show detected matches

imshow( "Good Matches", img_matches );
ROS_INFO("size matchings: %u", good_matches.size());
for(  i = 0; i < good_matches.size(); i++ )
{
  printf( "-- Good Match [%d] Keypoint 1: %d  -- Keypoint 2: %d  \n", i, ...
good_matches[i].queryIdx, good_matches[i].trainIdx );
}

 waitKey(1);
 return good_matches;
 }

at the point where ERROR is written i receive this error: OpenCV Error: Unsupported format or combination of formats (type=0 ) in buildIndex_, file /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1306/modules/flann/src/miniflann.cpp, line 299 terminate called after throwing an instance of 'cv::Exception' what(): /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1306/modules/flann/src/miniflann.cpp:299: error: (-210) type=0 in function buildIndex_

Aborted (core dumped)

But if I try the same code loading 2 JPG images it works!! what's wrong?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
5

answered 2013-04-10 04:59:10 -0600

berak gravatar image

updated 2013-04-10 05:01:03 -0600

there might be situations in real life, where it can't find features in both images, so you probably should check if the descriptors are valid before matching, i.e:

if ( descriptors_1.empty() )
   cvError(0,"MatchFinder","1st descriptor empty",__FILE__,__LINE__);    
if ( descriptors_2.empty() )
   cvError(0,"MatchFinder","2nd descriptor empty",__FILE__,__LINE__);
edit flag offensive delete link more

Comments

you are right!! the 2nd descriptor is empty. but...if the camera stays still why is the function able to find descriptors in the first frame but not in the second one?? thanks!

matteo gravatar imagematteo ( 2013-04-10 05:08:22 -0600 )edit

It can be due to varyating lightning conditions. Also if your camera has an autofocus function, please deactivate it, so your input is more constant.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-10 06:13:36 -0600 )edit

it's not the problem for sure: the image is exactly the same...i'm using a simulated camera in a simulated environment (v-rep).

matteo gravatar imagematteo ( 2013-04-10 06:45:23 -0600 )edit
0

answered 2019-07-13 11:34:35 -0600

try this

desc_2 = np.float32(desc_2)
edit flag offensive delete link more

Comments

yes, it helps

iamsimakov gravatar imageiamsimakov ( 2020-04-14 07:45:57 -0600 )edit

thanks, this works

yash281 gravatar imageyash281 ( 2020-07-23 08:54:51 -0600 )edit

This works. Brute force matcher accepts uint8 but FLANN matcher requires float32.

QitVision gravatar imageQitVision ( 2020-08-09 03:23:14 -0600 )edit
0

answered 2017-07-19 01:26:17 -0600

annusachan24 gravatar image

I had the same problem it seems that Flann needs the descriptors to be of type CV_32F. Try doing this before matching descriptors_1.convertTo(descriptors_1, CV_32F); descriptors_2.convertTo(descriptors_2, CV_32F);

edit flag offensive delete link more

Comments

unfortunately, your answer does not match the problem above, also while you're right about the FlannBased matcher needing float features, you MUST NOT try to convert e.g. ORB, binary features to float (it does not make any sense to convert bitstrings to numbers) , but use a BFMatcher with HAMMING norm instead.

berak gravatar imageberak ( 2017-07-19 01:31:27 -0600 )edit

For situations where the dataset is large and the speed matters a lot, using FLANN was the only option. This conversion was the need of the hour. Can't use SURF(need to pay for that), so the only option seems to be using ORB with FLANN. Any other suggestions in my case of usage??

annusachan24 gravatar imageannusachan24 ( 2017-07-19 02:00:15 -0600 )edit

it might be a good idea, to ask your own question about this.

berak gravatar imageberak ( 2017-07-19 02:17:11 -0600 )edit

This worked for me!! thanks.

SubMishMar gravatar imageSubMishMar ( 2017-11-10 18:08:39 -0600 )edit

Also worked for me.

pygosceles gravatar imagepygosceles ( 2018-03-22 15:01:24 -0600 )edit

that is ok !

psychiatrist gravatar imagepsychiatrist ( 2018-10-10 02:57:25 -0600 )edit

again, NO, it's NOT OK to convert binary descriptors to float.

if you can't use SIFT or SURF, use AKAZE(UPRIGHT)

berak gravatar imageberak ( 2018-10-10 03:03:04 -0600 )edit

Question Tools

Stats

Asked: 2013-04-10 04:51:00 -0600

Seen: 33,783 times

Last updated: Apr 10 '13