Bug in BOWKMeansTrainer or how to handle this?
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?
"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
So, then, what descriptors shall I use with BOW (that has just kmeans trainer)?
Is kmajority in opencv 2.4, or in 3?
anything, that has float descriptors natively, SIFT,SURF,DAISY(!),KAZE
you can check descriptorType() and defaultNorm()
the link above is build upon 2.4 (iirc)
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 :)
no, there's no kmajority function or class in either 2.4 or 3.0. you're safe there.