Ask Your Question

Revision history [back]

Here is the relevant part of the code to compute BoW with ORB:

for( all your images )
{
    // Detect interesting points
    orb(img, Mat(), keypoints, descriptors);
    // Keep characteristics of images for further clustering.
    characteristics.push_back(descriptors);
}
// Create the BOW object with K classes
BOWKMeansTrainer bow(K);
for( all your descriptors )
{
    // Convert characteristics vector to float
    // This is require by BOWTrainer class
    Mat descr;
    characteristics[k].convertTo(descr, CV_32F);
    // Add it to the BOW object
    bow.add(descr);
}
// Perform the clustering of stored vectors
Mat voc = bow.cluster();

You need to convert features from CV_8U to CV_32F, because bag of words object expects float descriptors. It is not required for SIFT or SURF descriptors because they are in float, as said by @berak.

If you have some issues with this code, please show us some relevant parts of yours.