Ask Your Question
1

Why does DescriptorMatcher::add takes vector of Mats?

asked 2012-07-18 13:14:23 -0500

Kirill Kornyakov gravatar image

DescriptorMatcher::add method (http://docs.opencv.org/modules/features2d/doc/commoninterfacesofdescriptormatchers.html#descriptormatcher-add) wants a vector of matrices with descriptors. So, even if I want to train matcher for only one image (object), I have to create a dummy vector, put my descriptors there and give this vector to the DescriptorMatcher.

Is there an elegant way to add descriptors without a temporary vector?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
5

answered 2012-07-18 15:03:57 -0500

Maria Dimashova gravatar image

updated 2012-07-20 01:42:52 -0500

Usually you don't want to train matcher for only one image :) The typical scenario of using the DescriptorMatcher::add method is matching to descriptors from several images, e.g. "textured object detection". So usually vector descriptors consists of several matrices of descriptors according to the number of training images. If you want to match with descriptors of only one image, the easiest way is to use

void DescriptorMatcher::match( const Mat& queryDescriptors, const Mat& trainDescriptors,
                               vector<DMatch>& matches, const Mat& mask=Mat() )

instead of sequence add(), train(), match(). BTW you can not to call train() manually, it will be called in the first call of match().

But if you have to add descriptors from trainig set of images by one, you can write

descriptorMatcher.add(vector<Mat>(1, currentImageDescriptors));

I think it's also elegant way.

edit flag offensive delete link more

Comments

1

Am I right that you're saying that I don't need FLANN if I have only one image? I was under impression that FLANN is good to use even for this case. Could you say, how many descriptors I need to see the speedup from FLANN after training?

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-07-18 15:08:42 -0500 )edit

The problem is not only with samples count, but with the dimensionality too. There are often no accurate algorithms for NN search that are more efficient than BF search in high dimensional space. E.g. for the classic kd-tree there is a rule of usage: samples count >> 2^dimension, otherwise it'll show BF time. Flann provides several efficient approches for high dimensional space, but it gives approximate NN. Info about precision and speedup of Flann you can find here http://people.cs.ubc.ca/~mariusm/uploads/FLANN/flann_visapp09.pdf, but they start with 100K of SIFT descriptors (this is not the case of one image).

Maria Dimashova gravatar imageMaria Dimashova ( 2012-07-19 01:02:14 -0500 )edit

For large training set we are forced to agree with approximate solution. Why we should use Flann for descriptors of one image?.. for the matching many times with keyframe on low mobile platform. Maybe.

Maria Dimashova gravatar imageMaria Dimashova ( 2012-07-19 01:02:49 -0500 )edit
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2012-07-18 13:14:23 -0500

Seen: 690 times

Last updated: Jul 20 '12