updated documentation on features2d; minor features2d changes

This commit is contained in:
Maria Dimashova 2010-11-23 17:00:55 +00:00
parent 562a3bd5ea
commit c6e43c385d
5 changed files with 436 additions and 362 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1448,9 +1448,9 @@ protected:
int levels; int levels;
}; };
/****************************************************************************************\ /*
* Dynamic Feature Detectors * * Dynamic Feature Detectors
\****************************************************************************************/ */
/** \brief an adaptively adjusting detector that iteratively detects until the desired number /** \brief an adaptively adjusting detector that iteratively detects until the desired number
* of features are detected. * of features are detected.
* Beware that this is not thread safe - as the adjustment of parameters breaks the const * Beware that this is not thread safe - as the adjustment of parameters breaks the const
@ -1630,7 +1630,7 @@ public:
* images Image collection. * images Image collection.
* keypoints Input keypoints collection. keypoints[i] is keypoints detected in images[i]. * keypoints Input keypoints collection. keypoints[i] is keypoints detected in images[i].
* Keypoints for which a descriptor cannot be computed are removed. * Keypoints for which a descriptor cannot be computed are removed.
* descriptors Descriptor collection. descriptors[i] is descriptors computed for keypoints[i]. * descriptors Descriptor collection. descriptors[i] are descriptors computed for set keypoints[i].
*/ */
void compute( const vector<Mat>& images, vector<vector<KeyPoint> >& keypoints, vector<Mat>& descriptors ) const; void compute( const vector<Mat>& images, vector<vector<KeyPoint> >& keypoints, vector<Mat>& descriptors ) const;
@ -1788,6 +1788,7 @@ public:
static const int PATCH_SIZE = 48; static const int PATCH_SIZE = 48;
static const int KERNEL_SIZE = 9; static const int KERNEL_SIZE = 9;
// bytes is a length of descriptor in bytes. It can be equal 16, 32 or 64 bytes.
BriefDescriptorExtractor( int bytes = 32 ); BriefDescriptorExtractor( int bytes = 32 );
virtual int descriptorSize() const; virtual int descriptorSize() const;
@ -1893,7 +1894,7 @@ struct CV_EXPORTS HammingLUT
/// @todo Variable-length version, maybe default size=0 and specialize /// @todo Variable-length version, maybe default size=0 and specialize
/// @todo Need to choose C/SSE4 at runtime, but amortize this at matcher level for efficiency... /// @todo Need to choose C/SSE4 at runtime, but amortize this at matcher level for efficiency...
struct Hamming struct CV_EXPORTS Hamming
{ {
typedef unsigned char ValueType; typedef unsigned char ValueType;
typedef int ResultType; typedef int ResultType;
@ -2370,10 +2371,10 @@ public:
* trainKeypoints Keypoints from the train image * trainKeypoints Keypoints from the train image
*/ */
// Classify keypoints from query image under one train image. // Classify keypoints from query image under one train image.
virtual void classify( const Mat& queryImage, vector<KeyPoint>& queryKeypoints, void classify( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
const Mat& trainImage, vector<KeyPoint>& trainKeypoints ) const; const Mat& trainImage, vector<KeyPoint>& trainKeypoints ) const;
// Classify keypoints from query image under train image collection. // Classify keypoints from query image under train image collection.
virtual void classify( const Mat& queryImage, vector<KeyPoint>& queryKeypoints ); void classify( const Mat& queryImage, vector<KeyPoint>& queryKeypoints );
/* /*
* Group of methods to match keypoints from image pair. * Group of methods to match keypoints from image pair.

View File

@ -84,6 +84,7 @@ void DescriptorExtractor::compute( const Mat& image, vector<KeyPoint>& keypoints
void DescriptorExtractor::compute( const vector<Mat>& imageCollection, vector<vector<KeyPoint> >& pointCollection, vector<Mat>& descCollection ) const void DescriptorExtractor::compute( const vector<Mat>& imageCollection, vector<vector<KeyPoint> >& pointCollection, vector<Mat>& descCollection ) const
{ {
CV_Assert( imageCollection.size() == pointCollection.size() );
descCollection.resize( imageCollection.size() ); descCollection.resize( imageCollection.size() );
for( size_t i = 0; i < imageCollection.size(); i++ ) for( size_t i = 0; i < imageCollection.size(); i++ )
compute( imageCollection[i], pointCollection[i], descCollection[i] ); compute( imageCollection[i], pointCollection[i], descCollection[i] );

View File

@ -591,7 +591,11 @@ void FlannBasedMatcher::radiusMatchImpl( const Mat& queryDescriptors, vector<vec
Ptr<DescriptorMatcher> createDescriptorMatcher( const string& descriptorMatcherType ) Ptr<DescriptorMatcher> createDescriptorMatcher( const string& descriptorMatcherType )
{ {
DescriptorMatcher* dm = 0; DescriptorMatcher* dm = 0;
if( !descriptorMatcherType.compare( "BruteForce" ) ) if( !descriptorMatcherType.compare( "FlannBased" ) )
{
dm = new FlannBasedMatcher();
}
else if( !descriptorMatcherType.compare( "BruteForce" ) ) // L2
{ {
dm = new BruteForceMatcher<L2<float> >(); dm = new BruteForceMatcher<L2<float> >();
} }
@ -599,10 +603,6 @@ Ptr<DescriptorMatcher> createDescriptorMatcher( const string& descriptorMatcherT
{ {
dm = new BruteForceMatcher<L1<float> >(); dm = new BruteForceMatcher<L1<float> >();
} }
else if ( !descriptorMatcherType.compare( "FlannBased" ) )
{
dm = new FlannBasedMatcher();
}
else if( !descriptorMatcherType.compare("BruteForce-Hamming") ) else if( !descriptorMatcherType.compare("BruteForce-Hamming") )
{ {
dm = new BruteForceMatcher<Hamming>(); dm = new BruteForceMatcher<Hamming>();
@ -611,10 +611,6 @@ Ptr<DescriptorMatcher> createDescriptorMatcher( const string& descriptorMatcherT
{ {
dm = new BruteForceMatcher<HammingLUT>(); dm = new BruteForceMatcher<HammingLUT>();
} }
else
{
//CV_Error( CV_StsBadArg, "unsupported descriptor matcher type");
}
return dm; return dm;
} }
@ -766,83 +762,83 @@ void GenericDescriptorMatcher::clear()
void GenericDescriptorMatcher::train() void GenericDescriptorMatcher::train()
{} {}
void GenericDescriptorMatcher::classify( const Mat& queryImage, vector<KeyPoint>& queryPoints, void GenericDescriptorMatcher::classify( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
const Mat& trainImage, vector<KeyPoint>& trainPoints ) const const Mat& trainImage, vector<KeyPoint>& trainKeypoints ) const
{ {
vector<DMatch> matches; vector<DMatch> matches;
match( queryImage, queryPoints, trainImage, trainPoints, matches ); match( queryImage, queryKeypoints, trainImage, trainKeypoints, matches );
// remap keypoint indices to descriptors // remap keypoint indices to descriptors
for( size_t i = 0; i < matches.size(); i++ ) for( size_t i = 0; i < matches.size(); i++ )
queryPoints[matches[i].queryIdx].class_id = trainPoints[matches[i].trainIdx].class_id; queryKeypoints[matches[i].queryIdx].class_id = trainKeypoints[matches[i].trainIdx].class_id;
} }
void GenericDescriptorMatcher::classify( const Mat& queryImage, vector<KeyPoint>& queryPoints ) void GenericDescriptorMatcher::classify( const Mat& queryImage, vector<KeyPoint>& queryKeypoints )
{ {
vector<DMatch> matches; vector<DMatch> matches;
match( queryImage, queryPoints, matches ); match( queryImage, queryKeypoints, matches );
// remap keypoint indices to descriptors // remap keypoint indices to descriptors
for( size_t i = 0; i < matches.size(); i++ ) for( size_t i = 0; i < matches.size(); i++ )
queryPoints[matches[i].queryIdx].class_id = trainPointCollection.getKeyPoint( matches[i].trainIdx, matches[i].trainIdx ).class_id; queryKeypoints[matches[i].queryIdx].class_id = trainPointCollection.getKeyPoint( matches[i].trainIdx, matches[i].trainIdx ).class_id;
} }
void GenericDescriptorMatcher::match( const Mat& queryImg, vector<KeyPoint>& queryPoints, void GenericDescriptorMatcher::match( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
const Mat& trainImg, vector<KeyPoint>& trainPoints, const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
vector<DMatch>& matches, const Mat& mask ) const vector<DMatch>& matches, const Mat& mask ) const
{ {
Ptr<GenericDescriptorMatcher> tempMatcher = clone( true ); Ptr<GenericDescriptorMatcher> tempMatcher = clone( true );
vector<vector<KeyPoint> > vecTrainPoints(1, trainPoints); vector<vector<KeyPoint> > vecTrainPoints(1, trainKeypoints);
tempMatcher->add( vector<Mat>(1, trainImg), vecTrainPoints ); tempMatcher->add( vector<Mat>(1, trainImage), vecTrainPoints );
tempMatcher->match( queryImg, queryPoints, matches, vector<Mat>(1, mask) ); tempMatcher->match( queryImage, queryKeypoints, matches, vector<Mat>(1, mask) );
vecTrainPoints[0].swap( trainPoints ); vecTrainPoints[0].swap( trainKeypoints );
} }
void GenericDescriptorMatcher::knnMatch( const Mat& queryImg, vector<KeyPoint>& queryPoints, void GenericDescriptorMatcher::knnMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
const Mat& trainImg, vector<KeyPoint>& trainPoints, const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
vector<vector<DMatch> >& matches, int knn, const Mat& mask, bool compactResult ) const vector<vector<DMatch> >& matches, int knn, const Mat& mask, bool compactResult ) const
{ {
Ptr<GenericDescriptorMatcher> tempMatcher = clone( true ); Ptr<GenericDescriptorMatcher> tempMatcher = clone( true );
vector<vector<KeyPoint> > vecTrainPoints(1, trainPoints); vector<vector<KeyPoint> > vecTrainPoints(1, trainKeypoints);
tempMatcher->add( vector<Mat>(1, trainImg), vecTrainPoints ); tempMatcher->add( vector<Mat>(1, trainImage), vecTrainPoints );
tempMatcher->knnMatch( queryImg, queryPoints, matches, knn, vector<Mat>(1, mask), compactResult ); tempMatcher->knnMatch( queryImage, queryKeypoints, matches, knn, vector<Mat>(1, mask), compactResult );
vecTrainPoints[0].swap( trainPoints ); vecTrainPoints[0].swap( trainKeypoints );
} }
void GenericDescriptorMatcher::radiusMatch( const Mat& queryImg, vector<KeyPoint>& queryPoints, void GenericDescriptorMatcher::radiusMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
const Mat& trainImg, vector<KeyPoint>& trainPoints, const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
vector<vector<DMatch> >& matches, float maxDistance, vector<vector<DMatch> >& matches, float maxDistance,
const Mat& mask, bool compactResult ) const const Mat& mask, bool compactResult ) const
{ {
Ptr<GenericDescriptorMatcher> tempMatcher = clone( true ); Ptr<GenericDescriptorMatcher> tempMatcher = clone( true );
vector<vector<KeyPoint> > vecTrainPoints(1, trainPoints); vector<vector<KeyPoint> > vecTrainPoints(1, trainKeypoints);
tempMatcher->add( vector<Mat>(1, trainImg), vecTrainPoints ); tempMatcher->add( vector<Mat>(1, trainImage), vecTrainPoints );
tempMatcher->radiusMatch( queryImg, queryPoints, matches, maxDistance, vector<Mat>(1, mask), compactResult ); tempMatcher->radiusMatch( queryImage, queryKeypoints, matches, maxDistance, vector<Mat>(1, mask), compactResult );
vecTrainPoints[0].swap( trainPoints ); vecTrainPoints[0].swap( trainKeypoints );
} }
void GenericDescriptorMatcher::match( const Mat& queryImg, vector<KeyPoint>& queryPoints, void GenericDescriptorMatcher::match( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
vector<DMatch>& matches, const vector<Mat>& masks ) vector<DMatch>& matches, const vector<Mat>& masks )
{ {
vector<vector<DMatch> > knnMatches; vector<vector<DMatch> > knnMatches;
knnMatch( queryImg, queryPoints, knnMatches, 1, masks, false ); knnMatch( queryImage, queryKeypoints, knnMatches, 1, masks, false );
convertMatches( knnMatches, matches ); convertMatches( knnMatches, matches );
} }
void GenericDescriptorMatcher::knnMatch( const Mat& queryImg, vector<KeyPoint>& queryPoints, void GenericDescriptorMatcher::knnMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
vector<vector<DMatch> >& matches, int knn, vector<vector<DMatch> >& matches, int knn,
const vector<Mat>& masks, bool compactResult ) const vector<Mat>& masks, bool compactResult )
{ {
train(); train();
knnMatchImpl( queryImg, queryPoints, matches, knn, masks, compactResult ); knnMatchImpl( queryImage, queryKeypoints, matches, knn, masks, compactResult );
} }
void GenericDescriptorMatcher::radiusMatch( const Mat& queryImg, vector<KeyPoint>& queryPoints, void GenericDescriptorMatcher::radiusMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
vector<vector<DMatch> >& matches, float maxDistance, vector<vector<DMatch> >& matches, float maxDistance,
const vector<Mat>& masks, bool compactResult ) const vector<Mat>& masks, bool compactResult )
{ {
train(); train();
radiusMatchImpl( queryImg, queryPoints, matches, maxDistance, masks, compactResult ); radiusMatchImpl( queryImage, queryKeypoints, matches, maxDistance, masks, compactResult );
} }
void GenericDescriptorMatcher::read( const FileNode& ) void GenericDescriptorMatcher::read( const FileNode& )
@ -920,7 +916,7 @@ bool OneWayDescriptorMatcher::isMaskSupported()
return false; return false;
} }
void OneWayDescriptorMatcher::knnMatchImpl( const Mat& queryImg, vector<KeyPoint>& queryPoints, void OneWayDescriptorMatcher::knnMatchImpl( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
vector<vector<DMatch> >& matches, int knn, vector<vector<DMatch> >& matches, int knn,
const vector<Mat>& /*masks*/, bool /*compactResult*/ ) const vector<Mat>& /*masks*/, bool /*compactResult*/ )
{ {
@ -928,30 +924,30 @@ void OneWayDescriptorMatcher::knnMatchImpl( const Mat& queryImg, vector<KeyPoint
CV_Assert( knn == 1 ); // knn > 1 unsupported because of bug in OneWayDescriptorBase for this case CV_Assert( knn == 1 ); // knn > 1 unsupported because of bug in OneWayDescriptorBase for this case
matches.resize( queryPoints.size() ); matches.resize( queryKeypoints.size() );
IplImage _qimage = queryImg; IplImage _qimage = queryImage;
for( size_t i = 0; i < queryPoints.size(); i++ ) for( size_t i = 0; i < queryKeypoints.size(); i++ )
{ {
int descIdx = -1, poseIdx = -1; int descIdx = -1, poseIdx = -1;
float distance; float distance;
base->FindDescriptor( &_qimage, queryPoints[i].pt, descIdx, poseIdx, distance ); base->FindDescriptor( &_qimage, queryKeypoints[i].pt, descIdx, poseIdx, distance );
matches[i].push_back( DMatch(i, descIdx, distance) ); matches[i].push_back( DMatch(i, descIdx, distance) );
} }
} }
void OneWayDescriptorMatcher::radiusMatchImpl( const Mat& queryImg, vector<KeyPoint>& queryPoints, void OneWayDescriptorMatcher::radiusMatchImpl( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
vector<vector<DMatch> >& matches, float maxDistance, vector<vector<DMatch> >& matches, float maxDistance,
const vector<Mat>& /*masks*/, bool /*compactResult*/ ) const vector<Mat>& /*masks*/, bool /*compactResult*/ )
{ {
train(); train();
matches.resize( queryPoints.size() ); matches.resize( queryKeypoints.size() );
IplImage _qimage = queryImg; IplImage _qimage = queryImage;
for( size_t i = 0; i < queryPoints.size(); i++ ) for( size_t i = 0; i < queryKeypoints.size(); i++ )
{ {
int descIdx = -1, poseIdx = -1; int descIdx = -1, poseIdx = -1;
float distance; float distance;
base->FindDescriptor( &_qimage, queryPoints[i].pt, descIdx, poseIdx, distance ); base->FindDescriptor( &_qimage, queryKeypoints[i].pt, descIdx, poseIdx, distance );
if( distance < maxDistance ) if( distance < maxDistance )
matches[i].push_back( DMatch(i, descIdx, distance) ); matches[i].push_back( DMatch(i, descIdx, distance) );
} }
@ -1064,18 +1060,18 @@ void FernDescriptorMatcher::calcBestProbAndMatchIdx( const Mat& image, const Poi
} }
} }
void FernDescriptorMatcher::knnMatchImpl( const Mat& queryImg, vector<KeyPoint>& queryPoints, void FernDescriptorMatcher::knnMatchImpl( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
vector<vector<DMatch> >& matches, int knn, vector<vector<DMatch> >& matches, int knn,
const vector<Mat>& /*masks*/, bool /*compactResult*/ ) const vector<Mat>& /*masks*/, bool /*compactResult*/ )
{ {
train(); train();
matches.resize( queryPoints.size() ); matches.resize( queryKeypoints.size() );
vector<float> signature( (size_t)classifier->getClassCount() ); vector<float> signature( (size_t)classifier->getClassCount() );
for( size_t queryIdx = 0; queryIdx < queryPoints.size(); queryIdx++ ) for( size_t queryIdx = 0; queryIdx < queryKeypoints.size(); queryIdx++ )
{ {
(*classifier)( queryImg, queryPoints[queryIdx].pt, signature); (*classifier)( queryImage, queryKeypoints[queryIdx].pt, signature);
for( int k = 0; k < knn; k++ ) for( int k = 0; k < knn; k++ )
{ {
@ -1099,17 +1095,17 @@ void FernDescriptorMatcher::knnMatchImpl( const Mat& queryImg, vector<KeyPoint>&
} }
} }
void FernDescriptorMatcher::radiusMatchImpl( const Mat& queryImg, vector<KeyPoint>& queryPoints, void FernDescriptorMatcher::radiusMatchImpl( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
vector<vector<DMatch> >& matches, float maxDistance, vector<vector<DMatch> >& matches, float maxDistance,
const vector<Mat>& /*masks*/, bool /*compactResult*/ ) const vector<Mat>& /*masks*/, bool /*compactResult*/ )
{ {
train(); train();
matches.resize( queryPoints.size() ); matches.resize( queryKeypoints.size() );
vector<float> signature( (size_t)classifier->getClassCount() ); vector<float> signature( (size_t)classifier->getClassCount() );
for( size_t i = 0; i < queryPoints.size(); i++ ) for( size_t i = 0; i < queryKeypoints.size(); i++ )
{ {
(*classifier)( queryImg, queryPoints[i].pt, signature); (*classifier)( queryImage, queryKeypoints[i].pt, signature);
for( int ci = 0; ci < classifier->getClassCount(); ci++ ) for( int ci = 0; ci < classifier->getClassCount(); ci++ )
{ {
@ -1206,21 +1202,21 @@ bool VectorDescriptorMatcher::isMaskSupported()
return matcher->isMaskSupported(); return matcher->isMaskSupported();
} }
void VectorDescriptorMatcher::knnMatchImpl( const Mat& queryImg, vector<KeyPoint>& queryPoints, void VectorDescriptorMatcher::knnMatchImpl( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
vector<vector<DMatch> >& matches, int knn, vector<vector<DMatch> >& matches, int knn,
const vector<Mat>& masks, bool compactResult ) const vector<Mat>& masks, bool compactResult )
{ {
Mat queryDescriptors; Mat queryDescriptors;
extractor->compute( queryImg, queryPoints, queryDescriptors ); extractor->compute( queryImage, queryKeypoints, queryDescriptors );
matcher->knnMatch( queryDescriptors, matches, knn, masks, compactResult ); matcher->knnMatch( queryDescriptors, matches, knn, masks, compactResult );
} }
void VectorDescriptorMatcher::radiusMatchImpl( const Mat& queryImg, vector<KeyPoint>& queryPoints, void VectorDescriptorMatcher::radiusMatchImpl( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
vector<vector<DMatch> >& matches, float maxDistance, vector<vector<DMatch> >& matches, float maxDistance,
const vector<Mat>& masks, bool compactResult ) const vector<Mat>& masks, bool compactResult )
{ {
Mat queryDescriptors; Mat queryDescriptors;
extractor->compute( queryImg, queryPoints, queryDescriptors ); extractor->compute( queryImage, queryKeypoints, queryDescriptors );
matcher->radiusMatch( queryDescriptors, matches, maxDistance, masks, compactResult ); matcher->radiusMatch( queryDescriptors, matches, maxDistance, masks, compactResult );
} }
@ -1245,7 +1241,8 @@ Ptr<GenericDescriptorMatcher> VectorDescriptorMatcher::clone( bool emptyTrainDat
/* /*
* Factory function for GenericDescriptorMatch creating * Factory function for GenericDescriptorMatch creating
*/ */
Ptr<GenericDescriptorMatcher> createGenericDescriptorMatcher( const string& genericDescritptorMatcherType, const string &paramsFilename ) Ptr<GenericDescriptorMatcher> createGenericDescriptorMatcher( const string& genericDescritptorMatcherType,
const string &paramsFilename )
{ {
Ptr<GenericDescriptorMatcher> descriptorMatcher; Ptr<GenericDescriptorMatcher> descriptorMatcher;
if( ! genericDescritptorMatcherType.compare("ONEWAY") ) if( ! genericDescritptorMatcherType.compare("ONEWAY") )
@ -1256,12 +1253,8 @@ Ptr<GenericDescriptorMatcher> createGenericDescriptorMatcher( const string& gene
{ {
descriptorMatcher = new FernDescriptorMatcher(); descriptorMatcher = new FernDescriptorMatcher();
} }
else if( ! genericDescritptorMatcherType.compare ("CALONDER") )
{
//descriptorMatch = new CalonderDescriptorMatch ();
}
if( !paramsFilename.empty() && descriptorMatcher != 0 ) if( !paramsFilename.empty() && !descriptorMatcher.empty() )
{ {
FileStorage fs = FileStorage( paramsFilename, FileStorage::READ ); FileStorage fs = FileStorage( paramsFilename, FileStorage::READ );
if( fs.isOpened() ) if( fs.isOpened() )

View File

@ -69,7 +69,7 @@ bool createDetectorDescriptorMatcher( const string& detectorType, const string&
bool isCreated = !( featureDetector.empty() || descriptorExtractor.empty() || descriptorMatcher.empty() ); bool isCreated = !( featureDetector.empty() || descriptorExtractor.empty() || descriptorMatcher.empty() );
if( !isCreated ) if( !isCreated )
cout << "Can not create feature detector or descriptor exstractor or descriptor matcher of given types." << endl << ">" << endl; cout << "Can not create feature detector or descriptor extractor or descriptor matcher of given types." << endl << ">" << endl;
return isCreated; return isCreated;
} }