Merge pull request #1290 from mbarnach:bow_desc
This commit is contained in:
commit
4fbd2ef87a
@ -124,6 +124,7 @@ The class declaration is the following: ::
|
|||||||
public:
|
public:
|
||||||
BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
|
BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
|
||||||
const Ptr<DescriptorMatcher>& dmatcher );
|
const Ptr<DescriptorMatcher>& dmatcher );
|
||||||
|
BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& dmatcher );
|
||||||
virtual ~BOWImgDescriptorExtractor(){}
|
virtual ~BOWImgDescriptorExtractor(){}
|
||||||
|
|
||||||
void setVocabulary( const Mat& vocabulary );
|
void setVocabulary( const Mat& vocabulary );
|
||||||
@ -132,6 +133,8 @@ The class declaration is the following: ::
|
|||||||
Mat& imgDescriptor,
|
Mat& imgDescriptor,
|
||||||
vector<vector<int> >* pointIdxsOfClusters=0,
|
vector<vector<int> >* pointIdxsOfClusters=0,
|
||||||
Mat* descriptors=0 );
|
Mat* descriptors=0 );
|
||||||
|
void compute( const Mat& descriptors, Mat& imgDescriptor,
|
||||||
|
std::vector<std::vector<int> >* pointIdxsOfClusters=0 );
|
||||||
int descriptorSize() const;
|
int descriptorSize() const;
|
||||||
int descriptorType() const;
|
int descriptorType() const;
|
||||||
|
|
||||||
@ -147,6 +150,7 @@ BOWImgDescriptorExtractor::BOWImgDescriptorExtractor
|
|||||||
The constructor.
|
The constructor.
|
||||||
|
|
||||||
.. ocv:function:: BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor, const Ptr<DescriptorMatcher>& dmatcher )
|
.. ocv:function:: BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor, const Ptr<DescriptorMatcher>& dmatcher )
|
||||||
|
.. ocv:function:: BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& dmatcher )
|
||||||
|
|
||||||
:param dextractor: Descriptor extractor that is used to compute descriptors for an input image and its keypoints.
|
:param dextractor: Descriptor extractor that is used to compute descriptors for an input image and its keypoints.
|
||||||
|
|
||||||
@ -177,11 +181,14 @@ BOWImgDescriptorExtractor::compute
|
|||||||
Computes an image descriptor using the set visual vocabulary.
|
Computes an image descriptor using the set visual vocabulary.
|
||||||
|
|
||||||
.. ocv:function:: void BOWImgDescriptorExtractor::compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& imgDescriptor, vector<vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 )
|
.. ocv:function:: void BOWImgDescriptorExtractor::compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& imgDescriptor, vector<vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 )
|
||||||
|
.. ocv:function:: void BOWImgDescriptorExtractor::compute( const Mat& keypointDescriptors, Mat& imgDescriptor, std::vector<std::vector<int> >* pointIdxsOfClusters=0 )
|
||||||
|
|
||||||
:param image: Image, for which the descriptor is computed.
|
:param image: Image, for which the descriptor is computed.
|
||||||
|
|
||||||
:param keypoints: Keypoints detected in the input image.
|
:param keypoints: Keypoints detected in the input image.
|
||||||
|
|
||||||
|
:param keypointDescriptors: Computed descriptors to match with vocabulary.
|
||||||
|
|
||||||
:param imgDescriptor: Computed output image descriptor.
|
:param imgDescriptor: Computed output image descriptor.
|
||||||
|
|
||||||
: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.
|
: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.
|
||||||
|
@ -1512,12 +1512,15 @@ class CV_EXPORTS BOWImgDescriptorExtractor
|
|||||||
public:
|
public:
|
||||||
BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
|
BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
|
||||||
const Ptr<DescriptorMatcher>& dmatcher );
|
const Ptr<DescriptorMatcher>& dmatcher );
|
||||||
|
BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& dmatcher );
|
||||||
virtual ~BOWImgDescriptorExtractor();
|
virtual ~BOWImgDescriptorExtractor();
|
||||||
|
|
||||||
void setVocabulary( const Mat& vocabulary );
|
void setVocabulary( const Mat& vocabulary );
|
||||||
const Mat& getVocabulary() const;
|
const Mat& getVocabulary() const;
|
||||||
void compute( const Mat& image, std::vector<KeyPoint>& keypoints, Mat& imgDescriptor,
|
void compute( const Mat& image, std::vector<KeyPoint>& keypoints, Mat& imgDescriptor,
|
||||||
std::vector<std::vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 );
|
std::vector<std::vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 );
|
||||||
|
void compute( const Mat& keypointDescriptors, Mat& imgDescriptor,
|
||||||
|
std::vector<std::vector<int> >* pointIdxsOfClusters=0 );
|
||||||
// compute() is not constant because DescriptorMatcher::match is not constant
|
// compute() is not constant because DescriptorMatcher::match is not constant
|
||||||
|
|
||||||
int descriptorSize() const;
|
int descriptorSize() const;
|
||||||
|
@ -121,6 +121,10 @@ BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorExtrac
|
|||||||
dextractor(_dextractor), dmatcher(_dmatcher)
|
dextractor(_dextractor), dmatcher(_dmatcher)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& _dmatcher ) :
|
||||||
|
dmatcher(_dmatcher)
|
||||||
|
{}
|
||||||
|
|
||||||
BOWImgDescriptorExtractor::~BOWImgDescriptorExtractor()
|
BOWImgDescriptorExtractor::~BOWImgDescriptorExtractor()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -137,22 +141,44 @@ const Mat& BOWImgDescriptorExtractor::getVocabulary() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BOWImgDescriptorExtractor::compute( const Mat& image, std::vector<KeyPoint>& keypoints, Mat& imgDescriptor,
|
void BOWImgDescriptorExtractor::compute( const Mat& image, std::vector<KeyPoint>& keypoints, Mat& imgDescriptor,
|
||||||
std::vector<std::vector<int> >* pointIdxsOfClusters, Mat* _descriptors )
|
std::vector<std::vector<int> >* pointIdxsOfClusters, Mat* descriptors )
|
||||||
{
|
{
|
||||||
imgDescriptor.release();
|
imgDescriptor.release();
|
||||||
|
|
||||||
if( keypoints.empty() )
|
if( keypoints.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int clusterCount = descriptorSize(); // = vocabulary.rows
|
|
||||||
|
|
||||||
// Compute descriptors for the image.
|
// Compute descriptors for the image.
|
||||||
Mat descriptors;
|
Mat _descriptors;
|
||||||
dextractor->compute( image, keypoints, descriptors );
|
dextractor->compute( image, keypoints, _descriptors );
|
||||||
|
|
||||||
|
compute( _descriptors, imgDescriptor, pointIdxsOfClusters );
|
||||||
|
|
||||||
|
// Add the descriptors of image keypoints
|
||||||
|
if (descriptors) {
|
||||||
|
*descriptors = _descriptors.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int BOWImgDescriptorExtractor::descriptorSize() const
|
||||||
|
{
|
||||||
|
return vocabulary.empty() ? 0 : vocabulary.rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BOWImgDescriptorExtractor::descriptorType() const
|
||||||
|
{
|
||||||
|
return CV_32FC1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BOWImgDescriptorExtractor::compute( const Mat& keypointDescriptors, Mat& imgDescriptor, std::vector<std::vector<int> >* pointIdxsOfClusters )
|
||||||
|
{
|
||||||
|
CV_Assert( vocabulary.empty() != false );
|
||||||
|
|
||||||
|
int clusterCount = descriptorSize(); // = vocabulary.rows
|
||||||
|
|
||||||
// Match keypoint descriptors to cluster center (to vocabulary)
|
// Match keypoint descriptors to cluster center (to vocabulary)
|
||||||
std::vector<DMatch> matches;
|
std::vector<DMatch> matches;
|
||||||
dmatcher->match( descriptors, matches );
|
dmatcher->match( keypointDescriptors, matches );
|
||||||
|
|
||||||
// Compute image descriptor
|
// Compute image descriptor
|
||||||
if( pointIdxsOfClusters )
|
if( pointIdxsOfClusters )
|
||||||
@ -175,22 +201,7 @@ void BOWImgDescriptorExtractor::compute( const Mat& image, std::vector<KeyPoint>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Normalize image descriptor.
|
// Normalize image descriptor.
|
||||||
imgDescriptor /= descriptors.rows;
|
imgDescriptor /= keypointDescriptors.rows;
|
||||||
|
|
||||||
// Add the descriptors of image keypoints
|
|
||||||
if (_descriptors) {
|
|
||||||
*_descriptors = descriptors.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int BOWImgDescriptorExtractor::descriptorSize() const
|
|
||||||
{
|
|
||||||
return vocabulary.empty() ? 0 : vocabulary.rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
int BOWImgDescriptorExtractor::descriptorType() const
|
|
||||||
{
|
|
||||||
return CV_32FC1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user