diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index 0a26ada961..b5a8554993 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -1252,8 +1252,8 @@ public: */ void detect( const vector& imageCollection, vector >& pointCollection, const vector& masks=vector() ) const; - virtual void read(const FileNode&) {} - virtual void write(FileStorage&) const {} + virtual void read( const FileNode& ) {} + virtual void write( FileStorage& ) const {} protected: /* @@ -1268,11 +1268,11 @@ protected: class CV_EXPORTS FastFeatureDetector : public FeatureDetector { public: - FastFeatureDetector( int _threshold = 1, bool _nonmaxSuppression = true ); + FastFeatureDetector( int _threshold=1, bool _nonmaxSuppression=true ); virtual void detect( const Mat& image, vector& keypoints, const Mat& mask=Mat() ) const; - virtual void read (const FileNode& fn); - virtual void write (FileStorage& fs) const; + virtual void read( const FileNode& fn ); + virtual void write( FileStorage& fs ) const; protected: int threshold; @@ -1287,8 +1287,8 @@ public: int _blockSize=3, bool _useHarrisDetector=false, double _k=0.04 ); virtual void detect( const Mat& image, vector& keypoints, const Mat& mask=Mat() ) const; - virtual void read (const FileNode& fn); - virtual void write (FileStorage& fs) const; + virtual void read( const FileNode& fn ); + virtual void write( FileStorage& fs ) const; protected: int maxCorners; @@ -1302,13 +1302,13 @@ protected: class CV_EXPORTS MserFeatureDetector : public FeatureDetector { public: - MserFeatureDetector( CvMSERParams params = cvMSERParams () ); + MserFeatureDetector( CvMSERParams params=cvMSERParams () ); MserFeatureDetector( int delta, int minArea, int maxArea, double maxVariation, double minDiversity, int maxEvolution, double areaThreshold, double minMargin, int edgeBlurSize ); virtual void detect( const Mat& image, vector& keypoints, const Mat& mask=Mat() ) const; - virtual void read (const FileNode& fn); - virtual void write (FileStorage& fs) const; + virtual void read( const FileNode& fn ); + virtual void write( FileStorage& fs ) const; protected: MSER mser; @@ -1321,8 +1321,8 @@ public: int lineThresholdBinarized=8, int suppressNonmaxSize=5 ); virtual void detect( const Mat& image, vector& keypoints, const Mat& mask=Mat() ) const; - virtual void read (const FileNode& fn); - virtual void write (FileStorage& fs) const; + virtual void read( const FileNode& fn ); + virtual void write( FileStorage& fs ) const; protected: StarDetector star; @@ -1339,8 +1339,8 @@ public: int angleMode=SIFT::CommonParams::FIRST_ANGLE ); virtual void detect( const Mat& image, vector& keypoints, const Mat& mask=Mat() ) const; - virtual void read (const FileNode& fn); - virtual void write (FileStorage& fs) const; + virtual void read( const FileNode& fn ); + virtual void write( FileStorage& fs ) const; protected: SIFT sift; @@ -1351,8 +1351,8 @@ class CV_EXPORTS SurfFeatureDetector : public FeatureDetector public: SurfFeatureDetector( double hessianThreshold = 400., int octaves = 3, int octaveLayers = 4 ); virtual void detect( const Mat& image, vector& keypoints, const Mat& mask=Mat() ) const; - virtual void read (const FileNode& fn); - virtual void write (FileStorage& fs) const; + virtual void read( const FileNode& fn ); + virtual void write( FileStorage& fs ) const; protected: SURF surf; @@ -1388,10 +1388,20 @@ protected: class CV_EXPORTS GridAdaptedFeatureDetector : public FeatureDetector { public: - GridAdaptedFeatureDetector( const Ptr& _detector, int _maxTotalKeypoints, - int _gridRows=4, int _gridCols=4 ); + /* + * detector Detector that will be adapted. + * maxTotalKeypoints Maximum count of keypoints detected on the image. Only the strongest keypoints + * will be keeped. + * gridRows Grid rows count. + * gridCols Grid column count. + */ + GridAdaptedFeatureDetector( const Ptr& detector, int maxTotalKeypoints, + int gridRows=4, int gridCols=4 ); virtual void detect( const Mat& image, vector& keypoints, const Mat& mask=Mat() ) const; + // todo read/write + virtual void read( const FileNode& fn ) {} + virtual void write( FileStorage& fs ) const {} protected: Ptr detector; @@ -1407,9 +1417,12 @@ protected: class PyramidAdaptedFeatureDetector : public FeatureDetector { public: - PyramidAdaptedFeatureDetector( const Ptr& _detector, int _levels=2 ); + PyramidAdaptedFeatureDetector( const Ptr& detector, int levels=2 ); virtual void detect( const Mat& image, vector& keypoints, const Mat& mask=Mat() ) const; + // todo read/write + virtual void read( const FileNode& fn ) {} + virtual void write( FileStorage& fs ) const {} protected: Ptr detector; @@ -1663,7 +1676,7 @@ struct CV_EXPORTS DMatch float distance; - //less is better + // less is better bool operator<( const DMatch &m) const { return distance < m.distance; @@ -1788,13 +1801,61 @@ protected: }; /* - * Next two functions are used to implement BruteForceMatcher class specialization + * Brute-force descriptor matcher. + * + * For each descriptor in the first set, this matcher finds the closest + * descriptor in the second set by trying each one. + * + * For efficiency, BruteForceMatcher is templated on the distance metric. + * For float descriptors, a common choice would be cv::L2. */ template -class BruteForceMatcher; +class CV_EXPORTS BruteForceMatcher : public DescriptorMatcher +{ +public: + BruteForceMatcher( Distance d = Distance() ) : distance(d) {} + virtual ~BruteForceMatcher() {} + + virtual void train() {} + virtual bool supportMask() { return true; } + +protected: + virtual Ptr cloneWithoutData() const { return new BruteForceMatcher(distance); } + + virtual void knnMatchImpl( const Mat& queryDescs, vector >& matches, int knn, + const vector& masks, bool compactResult ); + virtual void radiusMatchImpl( const Mat& queryDescs, vector >& matches, float maxDistance, + const vector& masks, bool compactResult ); + Distance distance; + +private: + /* + * Next two methods are used to implement specialization + */ + static void bfKnnMatchImpl( BruteForceMatcher& matcher, + const Mat& queryDescs, vector >& matches, int knn, + const vector& masks, bool compactResult ); + static void bfRadiusMatchImpl( BruteForceMatcher& matcher, + const Mat& queryDescs, vector >& matches, float maxDistance, + const vector& masks, bool compactResult ); +}; template -inline void bfKnnMatchImpl( BruteForceMatcher& matcher, +void BruteForceMatcher::knnMatchImpl( const Mat& queryDescs, vector >& matches, int knn, + const vector& masks, bool compactResult ) +{ + bfKnnMatchImpl( *this, queryDescs, matches, knn, masks, compactResult ); +} + +template +void BruteForceMatcher::radiusMatchImpl( const Mat& queryDescs, vector >& matches, float maxDistance, + const vector& masks, bool compactResult ) +{ + bfRadiusMatchImpl( *this, queryDescs, matches, maxDistance, masks, compactResult ); +} + +template +inline void BruteForceMatcher::bfKnnMatchImpl( BruteForceMatcher& matcher, const Mat& queryDescs, vector >& matches, int knn, const vector& masks, bool compactResult ) { @@ -1869,7 +1930,7 @@ inline void bfKnnMatchImpl( BruteForceMatcher& matcher, } template -inline void bfRadiusMatchImpl( BruteForceMatcher& matcher, +inline void BruteForceMatcher::bfRadiusMatchImpl( BruteForceMatcher& matcher, const Mat& queryDescs, vector >& matches, float maxDistance, const vector& masks, bool compactResult ) { @@ -1920,58 +1981,6 @@ inline void bfRadiusMatchImpl( BruteForceMatcher& matcher, } } -/* - * Brute-force descriptor matcher. - * - * For each descriptor in the first set, this matcher finds the closest - * descriptor in the second set by trying each one. - * - * For efficiency, BruteForceMatcher is templated on the distance metric. - * For float descriptors, a common choice would be cv::L2. - */ -template -class CV_EXPORTS BruteForceMatcher : public DescriptorMatcher -{ -public: - template - friend void bfKnnMatchImpl( BruteForceMatcher& matcher, - const Mat& queryDescs, vector >& matches, int knn, - const vector& masks, bool compactResult ); - template - friend void bfRadiusMatchImpl( BruteForceMatcher& matcher, - const Mat& queryDescs, vector >& matches, float maxDistance, - const vector& masks, bool compactResult ); - - BruteForceMatcher( Distance d = Distance() ) : distance(d) {} - virtual ~BruteForceMatcher() {} - - virtual void train() {} - virtual bool supportMask() { return true; } - -protected: - virtual Ptr cloneWithoutData() const { return new BruteForceMatcher(distance); } - - virtual void knnMatchImpl( const Mat& queryDescs, vector >& matches, int knn, - const vector& masks, bool compactResult ); - virtual void radiusMatchImpl( const Mat& queryDescs, vector >& matches, float maxDistance, - const vector& masks, bool compactResult ); - Distance distance; -}; - -template -void BruteForceMatcher::knnMatchImpl( const Mat& queryDescs, vector >& matches, int knn, - const vector& masks, bool compactResult ) -{ - bfKnnMatchImpl( *this, queryDescs, matches, knn, masks, compactResult ); -} - -template -void BruteForceMatcher::radiusMatchImpl( const Mat& queryDescs, vector >& matches, float maxDistance, - const vector& masks, bool compactResult ) -{ - bfRadiusMatchImpl( *this, queryDescs, matches, maxDistance, masks, compactResult ); -} - /* * BruteForceMatcher L2 specialization */ diff --git a/modules/features2d/src/detectors.cpp b/modules/features2d/src/detectors.cpp index ebd879af18..e9a837d60a 100644 --- a/modules/features2d/src/detectors.cpp +++ b/modules/features2d/src/detectors.cpp @@ -425,7 +425,7 @@ void GridAdaptedFeatureDetector::detect( const Mat& image, vector& key } /* - * GridAdaptedFeatureDetector + * PyramidAdaptedFeatureDetector */ PyramidAdaptedFeatureDetector::PyramidAdaptedFeatureDetector( const Ptr& _detector, int _levels ) : detector(_detector), levels(_levels) diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index 2b2d6e0051..07fb379f8b 100755 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -231,7 +231,7 @@ void BruteForceMatcher >::knnMatchImpl( const Mat& queryDescs, vector< const vector& masks, bool compactResult ) { #ifndef HAVE_EIGEN2 - bfKnnMatchImpl >( *this, queryDescs, matches, knn, masks, compactResult ); + bfKnnMatchImpl( *this, queryDescs, matches, knn, masks, compactResult ); #else CV_Assert( queryDescs.type() == CV_32FC1 || queryDescs.empty() ); CV_Assert( masks.empty() || masks.size() == trainDescCollection.size() ); @@ -319,7 +319,7 @@ void BruteForceMatcher >::radiusMatchImpl( const Mat& queryDescs, vect const vector& masks, bool compactResult ) { #ifndef HAVE_EIGEN2 - bfRadiusMatchImpl >( *this, queryDescs, matches, maxDistance, masks, compactResult ); + bfRadiusMatchImpl( *this, queryDescs, matches, maxDistance, masks, compactResult ); #else CV_Assert( queryDescs.type() == CV_32FC1 || queryDescs.empty() ); CV_Assert( masks.empty() || masks.size() == trainDescCollection.size() );