How can I get the histogram of words in a bag of words creation?

asked 2014-10-23 13:22:20 -0600

v3xd gravatar image

updated 2014-10-23 20:52:38 -0600

    String imName = "images/out/cropped";
//to store the current input image
Mat input;

//To store the keypoints that will be extracted by SIFT
vector<KeyPoint> keypoints;
//To store the SIFT descriptor of current image
Mat descriptor;
//To store all the descriptors that are extracted from all the images.
Mat featuresUnclustered;
//The SIFT feature extractor and descriptor
SiftDescriptorExtractor detector;
Mat bow_descs;
//feature descriptors and build the vocabulary
for(int i=0;i<10;i++)
{
    std::stringstream cntS;
    cntS << i;
    //open the file
    input = imread(imName + cntS.str()+".pgm", CV_LOAD_IMAGE_UNCHANGED);
    //detect feature points
    detector.detect(input, keypoints);
    //compute the descriptors for each keypoint
    detector.compute(input, keypoints, descriptor);
    //put the all feature descriptors in a single Mat object
    featuresUnclustered.push_back(descriptor);
}

//Construct BOWKMeansTrainer
//the number of bags
int dictionarySize=100;

//Create the BoW (or BoF) trainer
BOWKMeansTrainer bowTrainer(dictionarySize);
//cluster the feature vectors
Mat dictionary = bowTrainer.cluster(featuresUnclustered);
edit retag flag offensive close merge delete