Bug in BOWKMeansTrainer or how to handle this?

asked 2015-10-22 11:13:32 -0600

thdrksdfthmn gravatar image

I have used a BOWKMeansTrainer on FREAK descriptors and I got an error because of kmeans, so I have transformed the descriptors in CV_32F. When I tried a BOWImgDescriptorExtractor to match the descriptors of features in an image with the trained ones and it seems that I get another error:

 opencv/modules/features2d/src/matchers.cpp:351: error: (-215) queryDescriptors.type() == trainDescCollection[0].type() in function knnMatchImpl

I am sure that I use the same descriptors (FREAK) and the same matcher (BruteForce). The problem seems to be because of that transformation to float...

The idea is that I have 2 process: the train and the detection. In the train I use the BOWKMeansTrainer, that needs CV_32F descriptors, so I convert the descriptors into float, and then saved the clustered descriptors (aka vocabulary). The idea is that the vocabulary contains float descriptors. Is this a bug? Shouldn't this problem be handled in the cluster method?

Another question that I have is: Supposing that I have that vocabulary file and I read it, how do I know what type should it be? I know that FileStorage is saving the type, but because of the cluster that is returning a CV32F Mat, the type of the data in the file is float... Is there a doc where is mentioned what type of descriptors does each extractor returns?

edit retag flag offensive close merge delete

Comments

2

"so I have transformed the descriptors in CV_32F." - don't !

you just cannot apply kmeans on binary descriptors, it's not so much a format problem, but kmeans uses L2 distance, while you need hamming for binary descriptors.

in the end, to use BOW techniques for binary descriptors, you'd need a kmajority clustering, not a kmeans one. have a look e.g. here on how to implement kmajority

berak gravatar imageberak ( 2015-10-22 11:22:08 -0600 )edit

So, then, what descriptors shall I use with BOW (that has just kmeans trainer)?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-10-23 02:54:20 -0600 )edit

Is kmajority in opencv 2.4, or in 3?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-10-23 02:58:36 -0600 )edit

anything, that has float descriptors natively, SIFT,SURF,DAISY(!),KAZE

you can check descriptorType() and defaultNorm()

berak gravatar imageberak ( 2015-10-23 03:02:40 -0600 )edit

the link above is build upon 2.4 (iirc)

berak gravatar imageberak ( 2015-10-23 03:03:13 -0600 )edit

But it is not included in OpenCV 2.4 lib, I need to add it in my code, like in the link above... I just want to be sure that I do not create a class that is already in OpenCV :)

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-10-23 03:10:16 -0600 )edit
1

no, there's no kmajority function or class in either 2.4 or 3.0. you're safe there.

berak gravatar imageberak ( 2015-10-23 03:13:26 -0600 )edit