Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

Should I go through featuresUnclustered and see how many times each descriptor is repeated? Or after they have been clustered?

    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);

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

Should I go through featuresUnclustered and see I think I have to check how many times each descriptor cluster is repeated? Or after they have been clustered?repeated the matrix dictionary but I'm not sure if it is correct and I don't know the cleanest way of doing this.

    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);

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

I think I have to check how many times each cluster is repeated the matrix dictionary but I'm not sure if it is correct and I don't know the cleanest way of doing this.

[EDIT] Refrasing the question: how to show how many descriptors are located in the more dense clusters? String imName = "images/out/cropped"; //to store the current input image Mat input; 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);

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

I think I have to check how many times each cluster is repeated the matrix dictionary but I'm not sure if it is correct and I don't know the cleanest way of doing this.

[EDIT] Refrasing the question: how to show how many descriptors are located in the more dense clusters? clusters?

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

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);

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

I think I have to check how many times each cluster is repeated the matrix dictionary but I'm not sure if it is correct and I don't know the cleanest way of doing this.

[EDIT] Refrasing the question: how to show how many descriptors are located in the more dense clusters?

    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);