Some approaches based on local 2D features and used to object categorization are described in this section.
Abstract base class for training ‘’bag of visual words’’ vocabulary from a set of descriptors. See e.g. ‘’Visual Categorization with Bags of Keypoints’’ of Gabriella Csurka, Christopher R. Dance, Lixin Fan, Jutta Willamowski, Cedric Bray, 2004.
class BOWTrainer
{
public:
    BOWTrainer(){}
    virtual ~BOWTrainer(){}
    void add( const Mat& descriptors );
    const vector<Mat>& getDescriptors() const;
    int descripotorsCount() const;
    virtual void clear();
    virtual Mat cluster() const = 0;
    virtual Mat cluster( const Mat& descriptors ) const = 0;
protected:
    ...
};
Cluster train descriptors. Vocabulary consists from cluster centers. So this method
returns vocabulary. In first method variant the stored in object train descriptors will be clustered, in second variant – input descriptors will be clustered.
kmeans() based class to train visual vocabulary using the ‘’bag of visual words’’ approach.
class BOWKMeansTrainer : public BOWTrainer
{
public:
    BOWKMeansTrainer( int clusterCount, const TermCriteria& termcrit=TermCriteria(),
                      int attempts=3, int flags=KMEANS_PP_CENTERS );
    virtual ~BOWKMeansTrainer(){}
    // Returns trained vocabulary (i.e. cluster centers).
    virtual Mat cluster() const;
    virtual Mat cluster( const Mat& descriptors ) const;
protected:
    ...
};
To gain an understanding of constructor parameters see kmeans() function arguments.
2. Find nearest visual words from vocabulary for each keypoint descriptor, 3. Image descriptor is a normalized histogram of vocabulary words encountered in the image. I.e.
i -bin of the histogram is a frequency of i -word of vocabulary in the given image.
class BOWImgDescriptorExtractor
{
public:
    BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
                               const Ptr<DescriptorMatcher>& dmatcher );
    virtual ~BOWImgDescriptorExtractor(){}
    void setVocabulary( const Mat& vocabulary );
    const Mat& getVocabulary() const;
    void compute( const Mat& image, vector<KeyPoint>& keypoints,
                  Mat& imgDescriptor,
                  vector<vector<int> >* pointIdxsOfClusters=0,
                  Mat* descriptors=0 );
    int descriptorSize() const;
    int descriptorType() const;
protected:
    ...
};
Constructor.
| Parameters: | 
  | 
|---|
Compute image descriptor using set visual vocabulary.
| Parameters: | 
  | 
|---|
Returns image discriptor size, if vocabulary was set, and 0 otherwise.