Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to use BRIEF, ORB, FREAK or integer descriptor with cv::BOW?

What is the easiest way to use BRIEF, ORB, FREAK or integer based descriptor with opencv BOW implementation.

At this moment (based on http://answers.opencv.org/question/17460/how-to-use-bag-of-words-example-with-brief/) during the the dictionary build I do:

   orbDesc.compute(bwimage, keypoints_1, descriptors1);
   cv::Mat descr;
   descriptors1.convertTo(descr, CV_32F);
   featuresUnclustered.push_back(descr);

And I get the dictionary ( cv::BOWKMeansTrainer, withflags=cv::KMEANS_PP_CENTERS;), however when want o get the word histogram, I do this:

mymatcher=new cv::FlannBasedMatcher; 
...
myextractor=new cv::OrbDescriptorExtractor;
mydetector=new cv::OrbFeatureDetector;
myBOW=new cv::BOWImgDescriptorExtractor(myextractor,mymatcher);
myBOW->setVocabulary(dictionary);
std::vector<cv::KeyPoint> keypoints;
mydetector->detect(bwimage,keypoints);
cv::Mat bowDescriptor;
myBOW->compute(bwimage,keypoints,bowDescriptor);

However, the program breaks at myBOW->compute. This is because orb uses a non float vector. What is the easiest way for I solve this?

from the another post question there is this solution (convert the dictionary to unsigned char ):

cv::Mat floatdictonary; // 
floatDictionary = bowTrainer.cluster(floatFeaturesUnclustered);//you have convert features //unsigned char to float 
cv::Mat udictionary; 
floatdictionary.convertTo(udictonary,CV_8UC1); // 
 bowDE->setVocabulary(udictonary); 
 Mat bowDescriptor; std::vector<std::vector<int> > pointIdxOfClusters; 
 bowDE.compute(img, keypoints, bowDescriptor,&pointIdxOfClusters);

This last option is a good option?

thanks, Filipe