diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index a0ff4cc055..195eb6cc69 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -1583,7 +1583,7 @@ struct CV_EXPORTS L1 /* * Struct for matching: match index and distance between descriptors */ -struct DMatch +struct CV_EXPORTS DMatch { int indexTrain; int indexQuery; @@ -1683,25 +1683,6 @@ public: void match( const Mat& query, const Mat& mask, vector >& matches, float threshold ) const; - - - /* - * Find the best keypoint matches for small view changes. - * - * This function will only match descriptors whose keypoints have close enough - * image coordinates. - * - * keypoints_1 The first set of keypoints. - * descriptors_1 The first set of descriptors. - * keypoints_2 The second set of keypoints. - * descriptors_2 The second set of descriptors. - * maxDeltaX The maximum horizontal displacement. - * maxDeltaY The maximum vertical displacement. - * matches The matches between both sets. - */ - /*void matchWindowed( const vector& keypoints_1, const Mat& descriptors_1, - const vector& keypoints_2, const Mat& descriptors_2, - float maxDeltaX, float maxDeltaY, vector& matches) const;*/ virtual void clear(); protected: @@ -1728,64 +1709,6 @@ protected: } }; -inline void DescriptorMatcher::add( const Mat& descriptors ) -{ - if( train.empty() ) - { - train = descriptors; - } - else - { - // merge train and descriptors - Mat m( train.rows + descriptors.rows, train.cols, CV_32F ); - Mat m1 = m.rowRange( 0, train.rows ); - train.copyTo( m1 ); - Mat m2 = m.rowRange( train.rows + 1, m.rows ); - descriptors.copyTo( m2 ); - train = m; - } -} - -inline void DescriptorMatcher::match( const Mat& query, vector& matches ) const -{ - matchImpl( query, Mat(), matches ); -} - -inline void DescriptorMatcher::match( const Mat& query, const Mat& mask, - vector& matches ) const -{ - matchImpl( query, mask, matches ); -} - -inline void DescriptorMatcher::match( const Mat& query, vector& matches ) const -{ - matchImpl( query, Mat(), matches ); -} - - -inline void DescriptorMatcher::match( const Mat& query, const Mat& mask, - vector& matches ) const -{ - matchImpl( query, mask, matches ); -} - -inline void DescriptorMatcher::match( const Mat& query, vector >& matches, float threshold ) const -{ - matchImpl( query, Mat(), matches, threshold ); -} - -inline void DescriptorMatcher::match( const Mat& query, const Mat& mask, - vector >& matches, float threshold ) const -{ - matchImpl( query, mask, matches, threshold ); -} - - -inline void DescriptorMatcher::clear() -{ - train.release(); -} - /* * Brute-force descriptor matcher. * @@ -1912,7 +1835,6 @@ void BruteForceMatcher::matchImpl( const Mat& query, const Mat& mask, template<> void BruteForceMatcher >::matchImpl( const Mat& query, const Mat& mask, vector& matches ) const; -//void BruteForceMatcher >::matchImpl( const Mat& query, const Mat& mask, vector& matches ) const; CV_EXPORTS Ptr createDescriptorMatcher( const string& descriptorMatcherType ); @@ -2129,7 +2051,7 @@ public: virtual void classify( const Mat& image, vector& keypoints ); - virtual void clear (); + virtual void clear(); virtual void read( const FileNode &fn ); @@ -2160,7 +2082,7 @@ public: VectorDescriptorMatch( const Ptr& _extractor, const Ptr& _matcher ) : extractor( _extractor ), matcher( _matcher ) {} - ~VectorDescriptorMatch() {} + virtual ~VectorDescriptorMatch() {} // Builds flann index void index(); diff --git a/modules/features2d/src/descriptors.cpp b/modules/features2d/src/descriptors.cpp index a8bf2f7177..528afd4b40 100644 --- a/modules/features2d/src/descriptors.cpp +++ b/modules/features2d/src/descriptors.cpp @@ -427,8 +427,67 @@ Ptr createDescriptorMatcher( const string& descriptorMatcherT } /****************************************************************************************\ -* BruteForceMatcher L2 specialization * +* DescriptorMatcher * \****************************************************************************************/ +void DescriptorMatcher::add( const Mat& descriptors ) +{ + if( train.empty() ) + { + train = descriptors; + } + else + { + // merge train and descriptors + Mat m( train.rows + descriptors.rows, train.cols, CV_32F ); + Mat m1 = m.rowRange( 0, train.rows ); + train.copyTo( m1 ); + Mat m2 = m.rowRange( train.rows + 1, m.rows ); + descriptors.copyTo( m2 ); + train = m; + } +} + +void DescriptorMatcher::match( const Mat& query, vector& matches ) const +{ + matchImpl( query, Mat(), matches ); +} + +void DescriptorMatcher::match( const Mat& query, const Mat& mask, + vector& matches ) const +{ + matchImpl( query, mask, matches ); +} + +void DescriptorMatcher::match( const Mat& query, vector& matches ) const +{ + matchImpl( query, Mat(), matches ); +} + +void DescriptorMatcher::match( const Mat& query, const Mat& mask, + vector& matches ) const +{ + matchImpl( query, mask, matches ); +} + +void DescriptorMatcher::match( const Mat& query, vector >& matches, float threshold ) const +{ + matchImpl( query, Mat(), matches, threshold ); +} + +void DescriptorMatcher::match( const Mat& query, const Mat& mask, + vector >& matches, float threshold ) const +{ + matchImpl( query, mask, matches, threshold ); +} + +void DescriptorMatcher::clear() +{ + train.release(); +} + +/* + * BruteForceMatcher L2 specialization + */ template<> void BruteForceMatcher >::matchImpl( const Mat& query, const Mat& mask, vector& matches ) const {