2011-02-23 04:43:26 +08:00
|
|
|
Object Categorization
|
|
|
|
=====================
|
|
|
|
|
|
|
|
.. highlight:: cpp
|
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
Some approaches based on local 2D features and used to object categorization
|
2011-02-23 04:43:26 +08:00
|
|
|
are described in this section.
|
|
|
|
|
|
|
|
.. index:: BOWTrainer
|
|
|
|
|
|
|
|
.. _BOWTrainer:
|
|
|
|
|
|
|
|
BOWTrainer
|
|
|
|
----------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:type:: BOWTrainer
|
2011-02-23 04:43:26 +08:00
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
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. ::
|
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:
|
|
|
|
...
|
|
|
|
};
|
|
|
|
..
|
|
|
|
|
|
|
|
.. index:: BOWTrainer::add
|
|
|
|
|
2011-03-01 05:26:43 +08:00
|
|
|
BOWTrainer::add
|
2011-02-26 19:05:10 +08:00
|
|
|
------------------- ````
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:function:: void BOWTrainer::add( const Mat\& descriptors )
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
Add descriptors to training set. The training set will be clustered using clustermethod to construct vocabulary.
|
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
:param descriptors: Descriptors to add to training set. Each row of ``descriptors`` matrix is a one descriptor.
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
.. index:: BOWTrainer::getDescriptors
|
|
|
|
|
2011-03-01 05:26:43 +08:00
|
|
|
BOWTrainer::getDescriptors
|
2011-02-23 04:43:26 +08:00
|
|
|
------------------------------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:function:: const vector<Mat>\& BOWTrainer::getDescriptors() const
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
Returns training set of descriptors.
|
|
|
|
|
|
|
|
.. index:: BOWTrainer::descripotorsCount
|
|
|
|
|
2011-03-01 05:26:43 +08:00
|
|
|
BOWTrainer::descripotorsCount
|
2011-02-23 04:43:26 +08:00
|
|
|
---------------------------------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:function:: const vector<Mat>\& BOWTrainer::descripotorsCount() const
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
Returns count of all descriptors stored in the training set.
|
|
|
|
|
|
|
|
.. index:: BOWTrainer::cluster
|
|
|
|
|
2011-03-01 05:26:43 +08:00
|
|
|
BOWTrainer::cluster
|
2011-02-23 04:43:26 +08:00
|
|
|
-----------------------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:function:: Mat BOWTrainer::cluster() const
|
2011-02-23 04:43:26 +08:00
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
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
|
2011-02-23 04:43:26 +08:00
|
|
|
clustered, in second variant -- input descriptors will be clustered.
|
|
|
|
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:function:: Mat BOWTrainer::cluster( const Mat\& descriptors ) const
|
2011-02-23 04:43:26 +08:00
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
:param descriptors: Descriptors to cluster. Each row of ``descriptors`` matrix is a one descriptor. Descriptors will not be added
|
|
|
|
to the inner train descriptor set.
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
.. index:: BOWKMeansTrainer
|
|
|
|
|
|
|
|
.. _BOWKMeansTrainer:
|
|
|
|
|
|
|
|
BOWKMeansTrainer
|
|
|
|
----------------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:type:: BOWKMeansTrainer
|
2011-02-23 04:43:26 +08:00
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
:func:`kmeans` based class to train visual vocabulary using the ''bag of visual words'' approach. ::
|
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-02-26 19:05:10 +08:00
|
|
|
To gain an understanding of constructor parameters see
|
|
|
|
:func:`kmeans` function
|
2011-02-23 04:43:26 +08:00
|
|
|
arguments.
|
|
|
|
|
|
|
|
.. index:: BOWImgDescriptorExtractor
|
|
|
|
|
|
|
|
.. _BOWImgDescriptorExtractor:
|
|
|
|
|
|
|
|
BOWImgDescriptorExtractor
|
|
|
|
-------------------------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:type:: BOWImgDescriptorExtractor
|
2011-02-23 04:43:26 +08:00
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
Class to compute image descriptor using ''bad of visual words''. In few,
|
|
|
|
such computing consists from the following steps:
|
|
|
|
1. Compute descriptors for given image and it's keypoints set,
|
2011-02-23 04:43:26 +08:00
|
|
|
\
|
2011-02-26 19:05:10 +08:00
|
|
|
2. Find nearest visual words from vocabulary for each keypoint descriptor,
|
2011-02-23 04:43:26 +08:00
|
|
|
\
|
2011-02-26 19:05:10 +08:00
|
|
|
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. ::
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
class BOWImgDescriptorExtractor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
|
|
|
|
const Ptr<DescriptorMatcher>& dmatcher );
|
|
|
|
virtual ~BOWImgDescriptorExtractor(){}
|
2011-02-26 19:05:10 +08:00
|
|
|
|
2011-02-23 04:43:26 +08:00
|
|
|
void setVocabulary( const Mat& vocabulary );
|
|
|
|
const Mat& getVocabulary() const;
|
2011-02-26 19:05:10 +08:00
|
|
|
void compute( const Mat& image, vector<KeyPoint>& keypoints,
|
|
|
|
Mat& imgDescriptor,
|
|
|
|
vector<vector<int> >* pointIdxsOfClusters=0,
|
2011-02-23 04:43:26 +08:00
|
|
|
Mat* descriptors=0 );
|
|
|
|
int descriptorSize() const;
|
|
|
|
int descriptorType() const;
|
2011-02-26 19:05:10 +08:00
|
|
|
|
2011-02-23 04:43:26 +08:00
|
|
|
protected:
|
|
|
|
...
|
|
|
|
};
|
|
|
|
..
|
|
|
|
|
|
|
|
.. index:: BOWImgDescriptorExtractor::BOWImgDescriptorExtractor
|
|
|
|
|
2011-03-01 05:26:43 +08:00
|
|
|
BOWImgDescriptorExtractor::BOWImgDescriptorExtractor
|
2011-02-23 04:43:26 +08:00
|
|
|
--------------------------------------------------------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:function:: BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>\& dextractor, const Ptr<DescriptorMatcher>\& dmatcher )
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
Constructor.
|
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
:param dextractor: Descriptor extractor that will be used to compute descriptors
|
|
|
|
for input image and it's keypoints.
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
:param dmatcher: Descriptor matcher that will be used to find nearest word of trained vocabulary to
|
2011-02-26 19:05:10 +08:00
|
|
|
each keupoints descriptor of the image.
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
.. index:: BOWImgDescriptorExtractor::setVocabulary
|
|
|
|
|
2011-03-01 05:26:43 +08:00
|
|
|
BOWImgDescriptorExtractor::setVocabulary
|
2011-02-23 04:43:26 +08:00
|
|
|
--------------------------------------------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:function:: void BOWImgDescriptorExtractor::setVocabulary( const Mat\& vocabulary )
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
Method to set visual vocabulary.
|
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
:param vocabulary: Vocabulary (can be trained using inheritor of :func:`BOWTrainer` ).
|
|
|
|
Each row of vocabulary is a one visual word (cluster center).
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
.. index:: BOWImgDescriptorExtractor::getVocabulary
|
|
|
|
|
2011-03-01 05:26:43 +08:00
|
|
|
BOWImgDescriptorExtractor::getVocabulary
|
2011-02-23 04:43:26 +08:00
|
|
|
--------------------------------------------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:function:: const Mat\& BOWImgDescriptorExtractor::getVocabulary() const
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
Returns set vocabulary.
|
|
|
|
|
|
|
|
.. index:: BOWImgDescriptorExtractor::compute
|
|
|
|
|
2011-03-01 05:26:43 +08:00
|
|
|
BOWImgDescriptorExtractor::compute
|
2011-02-23 04:43:26 +08:00
|
|
|
--------------------------------------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:function:: void BOWImgDescriptorExtractor::compute( const Mat\& image, vector<KeyPoint>\& keypoints, Mat\& imgDescriptor, vector<vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 )
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
Compute image descriptor using set visual vocabulary.
|
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
:param image: The image. Image descriptor will be computed for this.
|
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
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
:param imgDescriptor: This is output, i.e. computed image descriptor.
|
2011-02-23 04:43:26 +08:00
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
:param pointIdxsOfClusters: Indices of keypoints which belong to the cluster, i.e. ``pointIdxsOfClusters[i]`` is keypoint indices which belong
|
|
|
|
to the ``i-`` cluster (word of vocabulary) (returned if it is not 0.)
|
2011-02-23 04:43:26 +08:00
|
|
|
|
2011-02-26 19:05:10 +08:00
|
|
|
:param descriptors: Descriptors of the image keypoints (returned if it is not 0.)
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
.. index:: BOWImgDescriptorExtractor::descriptorSize
|
|
|
|
|
2011-03-01 05:26:43 +08:00
|
|
|
BOWImgDescriptorExtractor::descriptorSize
|
2011-02-23 04:43:26 +08:00
|
|
|
---------------------------------------------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:function:: int BOWImgDescriptorExtractor::descriptorSize() const
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
Returns image discriptor size, if vocabulary was set, and 0 otherwise.
|
|
|
|
|
|
|
|
.. index:: BOWImgDescriptorExtractor::descriptorType
|
|
|
|
|
2011-03-01 05:26:43 +08:00
|
|
|
BOWImgDescriptorExtractor::descriptorType
|
2011-02-23 04:43:26 +08:00
|
|
|
---------------------------------------------
|
2011-03-01 05:26:43 +08:00
|
|
|
.. c:function:: int BOWImgDescriptorExtractor::descriptorType() const
|
2011-02-23 04:43:26 +08:00
|
|
|
|
|
|
|
Returns image descriptor type.
|
|
|
|
|