2011-02-23 04:43:26 +08:00
Object Categorization
=====================
.. highlight :: cpp
2011-05-08 23:30:00 +08:00
This section describes approaches based on local 2D features and used to categorize objects.
2011-02-23 04:43:26 +08:00
BOWTrainer
----------
2011-06-16 20:48:23 +08:00
.. ocv:class :: BOWTrainer
2011-02-23 04:43:26 +08:00
2011-05-08 23:30:00 +08:00
Abstract base class for training the *bag of visual words* vocabulary from a set of descriptors.
2011-05-08 17:31:15 +08:00
For details, see, for example, *Visual Categorization with Bags of Keypoints* by Gabriella Csurka, Christopher R. Dance,
2011-02-26 19:05:10 +08:00
Lixin Fan, Jutta Willamowski, Cedric Bray, 2004. ::
2011-02-23 04:43:26 +08:00
class BOWTrainer
{
public:
BOWTrainer(){}
virtual ~BOWTrainer(){}
2011-02-26 19:05:10 +08:00
2011-02-23 04:43:26 +08:00
void add( const Mat& descriptors );
const vector<Mat>& getDescriptors() const;
int descripotorsCount() const;
2011-02-26 19:05:10 +08:00
2011-02-23 04:43:26 +08:00
virtual void clear();
2011-02-26 19:05:10 +08:00
2011-02-23 04:43:26 +08:00
virtual Mat cluster() const = 0;
virtual Mat cluster( const Mat& descriptors ) const = 0;
2011-02-26 19:05:10 +08:00
2011-02-23 04:43:26 +08:00
protected:
...
};
2011-03-03 15:29:55 +08:00
2011-03-01 05:26:43 +08:00
BOWTrainer::add
2011-03-03 15:29:55 +08:00
-------------------
2012-10-18 01:42:09 +08:00
Adds descriptors to a training set.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
.. ocv:function :: void BOWTrainer::add( const Mat& descriptors )
2011-02-23 04:43:26 +08:00
2011-05-08 17:31:15 +08:00
:param descriptors: Descriptors to add to a training set. Each row of the ``descriptors`` matrix is a descriptor.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
The training set is clustered using `` clustermethod `` to construct the vocabulary.
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
BOWTrainer::getDescriptors
2011-02-23 04:43:26 +08:00
------------------------------
2011-06-30 06:06:42 +08:00
Returns a training set of descriptors.
2011-06-16 20:48:23 +08:00
.. ocv:function :: const vector<Mat>& BOWTrainer::getDescriptors() const
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
BOWTrainer::descripotorsCount
2011-02-23 04:43:26 +08:00
---------------------------------
2011-06-30 06:06:42 +08:00
Returns the count of all descriptors stored in the training set.
2012-05-28 15:36:14 +08:00
.. ocv:function :: int BOWTrainer::descripotorsCount() const
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
BOWTrainer::cluster
2011-02-23 04:43:26 +08:00
-----------------------
2012-10-18 01:42:09 +08:00
Clusters train descriptors.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
.. ocv:function :: Mat BOWTrainer::cluster() const
2011-02-23 04:43:26 +08:00
2011-06-16 20:48:23 +08:00
.. ocv:function :: Mat BOWTrainer::cluster( const Mat& descriptors ) const
2011-02-23 04:43:26 +08:00
2011-05-08 17:31:15 +08:00
:param descriptors: Descriptors to cluster. Each row of the ``descriptors`` matrix is a descriptor. Descriptors are not added to the inner train descriptor set.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
The vocabulary consists of cluster centers. So, this method returns the vocabulary. In the first variant of the method, train descriptors stored in the object are clustered. In the second variant, input descriptors are clustered.
2011-02-23 04:43:26 +08:00
BOWKMeansTrainer
----------------
2012-05-28 15:36:14 +08:00
.. ocv:class :: BOWKMeansTrainer : public BOWTrainer
2011-02-23 04:43:26 +08:00
2011-06-23 20:00:09 +08:00
:ocv:func: `kmeans` -based class to train visual vocabulary using the *bag of visual words* approach.
2011-06-17 21:23:28 +08:00
::
2011-02-23 04:43:26 +08:00
class BOWKMeansTrainer : public BOWTrainer
{
public:
BOWKMeansTrainer( int clusterCount, const TermCriteria& termcrit=TermCriteria(),
int attempts=3, int flags=KMEANS_PP_CENTERS );
virtual ~BOWKMeansTrainer(){}
2011-02-26 19:05:10 +08:00
2011-02-23 04:43:26 +08:00
// Returns trained vocabulary (i.e. cluster centers).
virtual Mat cluster() const;
virtual Mat cluster( const Mat& descriptors ) const;
2011-02-26 19:05:10 +08:00
2011-02-23 04:43:26 +08:00
protected:
...
};
2011-03-03 15:29:55 +08:00
2011-06-17 21:23:28 +08:00
BOWKMeansTrainer::BOWKMeansTrainer
2011-06-30 06:06:42 +08:00
----------------------------------
2011-06-30 08:41:41 +08:00
2011-06-30 06:06:42 +08:00
The constructor.
2011-07-01 17:39:22 +08:00
.. ocv:function :: BOWKMeansTrainer::BOWKMeansTrainer( int clusterCount, const TermCriteria& termcrit=TermCriteria(), int attempts=3, int flags=KMEANS_PP_CENTERS )
2011-02-23 04:43:26 +08:00
2011-06-23 20:00:09 +08:00
See :ocv:func: `kmeans` function parameters.
2011-02-23 04:43:26 +08:00
BOWImgDescriptorExtractor
-------------------------
2011-06-16 20:48:23 +08:00
.. ocv:class :: BOWImgDescriptorExtractor
2011-02-23 04:43:26 +08:00
2011-06-23 20:00:09 +08:00
Class to compute an image descriptor using the *bag of visual words* . Such a computation consists of the following steps:
2011-02-23 04:43:26 +08:00
2011-05-08 17:31:15 +08:00
#. Compute descriptors for a given image and its keypoints set.
#. Find the nearest visual words from the vocabulary for each keypoint descriptor.
2011-05-12 07:31:50 +08:00
#. Compute the bag-of-words image descriptor as is a normalized histogram of vocabulary words encountered in the image. The `` i `` -th bin of the histogram is a frequency of `` i `` -th word of the vocabulary in the given image.
2012-10-18 01:42:09 +08:00
2011-06-23 20:00:09 +08:00
The class declaration is the following: ::
2011-03-03 15:29:55 +08:00
class BOWImgDescriptorExtractor
{
public:
BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
const Ptr<DescriptorMatcher>& dmatcher );
2013-09-05 12:05:54 +08:00
BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& dmatcher );
2011-03-03 15:29:55 +08:00
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 );
2013-09-05 12:05:54 +08:00
void compute( const Mat& descriptors, Mat& imgDescriptor,
std::vector<std::vector<int> >* pointIdxsOfClusters=0 );
2011-03-03 15:29:55 +08:00
int descriptorSize() const;
int descriptorType() const;
protected:
...
};
2011-02-26 19:05:10 +08:00
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
BOWImgDescriptorExtractor::BOWImgDescriptorExtractor
2011-02-23 04:43:26 +08:00
--------------------------------------------------------
2011-06-30 06:06:42 +08:00
The constructor.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
.. ocv:function :: BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor, const Ptr<DescriptorMatcher>& dmatcher )
2013-09-05 12:05:54 +08:00
.. ocv:function :: BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& dmatcher )
2011-02-23 04:43:26 +08:00
2011-05-08 17:31:15 +08:00
:param dextractor: Descriptor extractor that is used to compute descriptors for an input image and its keypoints.
2011-02-23 04:43:26 +08:00
2011-05-08 17:31:15 +08:00
:param dmatcher: Descriptor matcher that is used to find the nearest word of the trained vocabulary for each keypoint descriptor of the image.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
BOWImgDescriptorExtractor::setVocabulary
2011-02-23 04:43:26 +08:00
--------------------------------------------
2011-06-30 06:06:42 +08:00
Sets a visual vocabulary.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
.. ocv:function :: void BOWImgDescriptorExtractor::setVocabulary( const Mat& vocabulary )
2011-02-23 04:43:26 +08:00
2011-06-23 20:00:09 +08:00
:param vocabulary: Vocabulary (can be trained using the inheritor of :ocv:class:`BOWTrainer` ). Each row of the vocabulary is a visual word (cluster center).
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
BOWImgDescriptorExtractor::getVocabulary
2011-02-23 04:43:26 +08:00
--------------------------------------------
2011-06-30 06:06:42 +08:00
Returns the set vocabulary.
2011-06-16 20:48:23 +08:00
.. ocv:function :: const Mat& BOWImgDescriptorExtractor::getVocabulary() const
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
BOWImgDescriptorExtractor::compute
2011-02-23 04:43:26 +08:00
--------------------------------------
2011-06-30 06:06:42 +08:00
Computes an image descriptor using the set visual vocabulary.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
.. ocv:function :: void BOWImgDescriptorExtractor::compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& imgDescriptor, vector<vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 )
2013-09-05 12:05:54 +08:00
.. ocv:function :: void BOWImgDescriptorExtractor::compute( const Mat& descriptors, Mat& imgDescriptor, std::vector<std::vector<int> >* pointIdxsOfClusters )
2011-02-23 04:43:26 +08:00
2011-05-12 07:31:50 +08:00
:param image: Image, for which the descriptor is computed.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
:param keypoints: Keypoints detected in the input image.
2011-02-23 04:43:26 +08:00
2013-09-05 12:05:54 +08:00
:param descriptors: Computed descriptors to match with vocabulary.
2011-05-08 23:30:00 +08:00
:param imgDescriptor: Computed output image descriptor.
2011-02-23 04:43:26 +08:00
2011-05-08 17:31:15 +08:00
:param pointIdxsOfClusters: Indices of keypoints that belong to the cluster. This means that ``pointIdxsOfClusters[i]`` are keypoint indices that belong to the ``i`` -th cluster (word of vocabulary) returned if it is non-zero.
2011-02-23 04:43:26 +08:00
2011-05-08 17:31:15 +08:00
:param descriptors: Descriptors of the image keypoints that are returned if they are non-zero.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
BOWImgDescriptorExtractor::descriptorSize
2011-02-23 04:43:26 +08:00
---------------------------------------------
2012-04-14 05:50:59 +08:00
Returns an image descriptor size if the vocabulary is set. Otherwise, it returns 0.
2011-06-30 06:06:42 +08:00
2011-06-16 20:48:23 +08:00
.. ocv:function :: int BOWImgDescriptorExtractor::descriptorSize() const
2011-02-23 04:43:26 +08:00
2011-03-01 05:26:43 +08:00
BOWImgDescriptorExtractor::descriptorType
2011-02-23 04:43:26 +08:00
---------------------------------------------
2011-06-30 08:41:41 +08:00
2011-06-30 06:06:42 +08:00
Returns an image descriptor type.
2011-02-23 04:43:26 +08:00
2011-06-30 06:06:42 +08:00
.. ocv:function :: int BOWImgDescriptorExtractor::descriptorType() const
2011-02-23 04:43:26 +08:00