From 5a730d09cdccbe7b6a61d71f571b4cda37ae54c9 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Mon, 15 Oct 2012 21:09:24 +0400 Subject: [PATCH] Fix binary compatibility of opencv_features2d --- .../include/opencv2/features2d/features2d.hpp | 9 ++++---- modules/features2d/perf/perf_fast.cpp | 7 ++++-- modules/features2d/src/brisk.cpp | 6 +++--- modules/features2d/src/fast.cpp | 25 ++++++++++++++++------ modules/features2d/src/fast_score.hpp | 13 +++++++++++ modules/features2d/src/features2d_init.cpp | 6 ++++++ modules/features2d/test/test_fast.cpp | 4 ++-- 7 files changed, 52 insertions(+), 18 deletions(-) diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index 0b6d884..ad9ecd6 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -566,19 +566,19 @@ protected: CV_EXPORTS void FAST( InputArray image, CV_OUT vector& keypoints, int threshold, bool nonmaxSupression=true ); -CV_EXPORTS void FAST( InputArray image, CV_OUT vector& keypoints, +CV_EXPORTS void FASTX( InputArray image, CV_OUT vector& keypoints, int threshold, bool nonmaxSupression, int type ); class CV_EXPORTS_W FastFeatureDetector : public FeatureDetector { public: + enum - { + { // Define it in old class to simplify migration to 2.5 TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2 }; - CV_WRAP FastFeatureDetector( int threshold=10, bool nonmaxSuppression=true); - CV_WRAP FastFeatureDetector( int threshold, bool nonmaxSuppression, int type); + CV_WRAP FastFeatureDetector( int threshold=10, bool nonmaxSuppression=true ); AlgorithmInfo* info() const; protected: @@ -586,7 +586,6 @@ protected: int threshold; bool nonmaxSuppression; - short type; }; diff --git a/modules/features2d/perf/perf_fast.cpp b/modules/features2d/perf/perf_fast.cpp index f550f7b..52411dd 100644 --- a/modules/features2d/perf/perf_fast.cpp +++ b/modules/features2d/perf/perf_fast.cpp @@ -30,10 +30,13 @@ PERF_TEST_P(fast, detect, testing::Combine( declare.in(frame); - FastFeatureDetector fd(20, true, type); + Ptr fd = Algorithm::create("Feature2D.FASTX"); + fd->set("threshold", 20); + fd->set("nonmaxSuppression", true); + fd->set("type", type); vector points; - TEST_CYCLE() fd.detect(frame, points); + TEST_CYCLE() fd->detect(frame, points); SANITY_CHECK_KEYPOINTS(points); } diff --git a/modules/features2d/src/brisk.cpp b/modules/features2d/src/brisk.cpp index 066817c..ad8c698 100755 --- a/modules/features2d/src/brisk.cpp +++ b/modules/features2d/src/brisk.cpp @@ -121,7 +121,7 @@ private: float scale_; float offset_; // agast - cv::Ptr fast_9_16_; + cv::Ptr fast_9_16_; int pixel_5_8_[25]; int pixel_9_16_[25]; }; @@ -2000,7 +2000,7 @@ BriskLayer::BriskLayer(const cv::Mat& img_in, float scale_in, float offset_in) scale_ = scale_in; offset_ = offset_in; // create an agast detector - fast_9_16_ = new FastFeatureDetector(1, true, FastFeatureDetector::TYPE_9_16); + fast_9_16_ = new FastFeatureDetector2(1, true, FastFeatureDetector::TYPE_9_16); makeOffsets(pixel_5_8_, (int)img_.step, 8); makeOffsets(pixel_9_16_, (int)img_.step, 16); } @@ -2022,7 +2022,7 @@ BriskLayer::BriskLayer(const BriskLayer& layer, int mode) offset_ = 0.5f * scale_ - 0.5f; } scores_ = cv::Mat::zeros(img_.rows, img_.cols, CV_8U); - fast_9_16_ = new FastFeatureDetector(1, false, FastFeatureDetector::TYPE_9_16); + fast_9_16_ = new FastFeatureDetector2(1, false, FastFeatureDetector::TYPE_9_16); makeOffsets(pixel_5_8_, (int)img_.step, 8); makeOffsets(pixel_9_16_, (int)img_.step, 16); } diff --git a/modules/features2d/src/fast.cpp b/modules/features2d/src/fast.cpp index ec0f335..92d57e0 100644 --- a/modules/features2d/src/fast.cpp +++ b/modules/features2d/src/fast.cpp @@ -245,7 +245,7 @@ void FAST_t(InputArray _img, std::vector& keypoints, int threshold, bo } } -void FAST(InputArray _img, std::vector& keypoints, int threshold, bool nonmax_suppression, int type) +void FASTX(InputArray _img, std::vector& keypoints, int threshold, bool nonmax_suppression, int type) { switch(type) { case FastFeatureDetector::TYPE_5_8: @@ -262,24 +262,37 @@ void FAST(InputArray _img, std::vector& keypoints, int threshold, bool void FAST(InputArray _img, std::vector& keypoints, int threshold, bool nonmax_suppression) { - FAST(_img, keypoints, threshold, nonmax_suppression, FastFeatureDetector::TYPE_9_16); + FASTX(_img, keypoints, threshold, nonmax_suppression, FastFeatureDetector::TYPE_9_16); } + /* * FastFeatureDetector */ FastFeatureDetector::FastFeatureDetector( int _threshold, bool _nonmaxSuppression ) - : threshold(_threshold), nonmaxSuppression(_nonmaxSuppression), type(FastFeatureDetector::TYPE_9_16) + : threshold(_threshold), nonmaxSuppression(_nonmaxSuppression) +{} + +FastFeatureDetector2::FastFeatureDetector2( int _threshold, bool _nonmaxSuppression ) + : FastFeatureDetector(_threshold, _nonmaxSuppression), type(FastFeatureDetector::TYPE_9_16) {} -FastFeatureDetector::FastFeatureDetector( int _threshold, bool _nonmaxSuppression, int _type ) -: threshold(_threshold), nonmaxSuppression(_nonmaxSuppression), type((short)_type) +FastFeatureDetector2::FastFeatureDetector2( int _threshold, bool _nonmaxSuppression, int _type ) + : FastFeatureDetector(_threshold, _nonmaxSuppression), type((short)_type) {} void FastFeatureDetector::detectImpl( const Mat& image, vector& keypoints, const Mat& mask ) const { Mat grayImage = image; if( image.type() != CV_8U ) cvtColor( image, grayImage, CV_BGR2GRAY ); - FAST( grayImage, keypoints, threshold, nonmaxSuppression, type ); + FAST( grayImage, keypoints, threshold, nonmaxSuppression ); + KeyPointsFilter::runByPixelsMask( keypoints, mask ); +} + +void FastFeatureDetector2::detectImpl( const Mat& image, vector& keypoints, const Mat& mask ) const +{ + Mat grayImage = image; + if( image.type() != CV_8U ) cvtColor( image, grayImage, CV_BGR2GRAY ); + FASTX( grayImage, keypoints, threshold, nonmaxSuppression, type ); KeyPointsFilter::runByPixelsMask( keypoints, mask ); } diff --git a/modules/features2d/src/fast_score.hpp b/modules/features2d/src/fast_score.hpp index 4884c73..f009f50 100644 --- a/modules/features2d/src/fast_score.hpp +++ b/modules/features2d/src/fast_score.hpp @@ -56,6 +56,19 @@ void makeOffsets(int pixel[25], int row_stride, int patternSize); template int cornerScore(const uchar* ptr, const int pixel[], int threshold); +class FastFeatureDetector2 : public FastFeatureDetector +{ +public: + CV_WRAP FastFeatureDetector2( int threshold=10, bool nonmaxSuppression=true); + CV_WRAP FastFeatureDetector2( int threshold, bool nonmaxSuppression, int type); + AlgorithmInfo* info() const; + +protected: + virtual void detectImpl( const Mat& image, vector& keypoints, const Mat& mask=Mat() ) const; + + short type; +}; + } #endif diff --git a/modules/features2d/src/features2d_init.cpp b/modules/features2d/src/features2d_init.cpp index af3bcd0..8c5222b 100644 --- a/modules/features2d/src/features2d_init.cpp +++ b/modules/features2d/src/features2d_init.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include "fast_score.hpp" using namespace cv; @@ -69,6 +70,10 @@ CV_INIT_ALGORITHM(BriefDescriptorExtractor, "Feature2D.BRIEF", CV_INIT_ALGORITHM(FastFeatureDetector, "Feature2D.FAST", obj.info()->addParam(obj, "threshold", obj.threshold); + obj.info()->addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression)); + +CV_INIT_ALGORITHM(FastFeatureDetector2, "Feature2D.FASTX", + obj.info()->addParam(obj, "threshold", obj.threshold); obj.info()->addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression); obj.info()->addParam(obj, "type", obj.type)); @@ -167,6 +172,7 @@ bool cv::initModule_features2d(void) all &= !BriefDescriptorExtractor_info_auto.name().empty(); all &= !BRISK_info_auto.name().empty(); all &= !FastFeatureDetector_info_auto.name().empty(); + all &= !FastFeatureDetector2_info_auto.name().empty(); all &= !StarDetector_info_auto.name().empty(); all &= !MSER_info_auto.name().empty(); all &= !FREAK_info_auto.name().empty(); diff --git a/modules/features2d/test/test_fast.cpp b/modules/features2d/test/test_fast.cpp index cdf9c89..4161be1 100644 --- a/modules/features2d/test/test_fast.cpp +++ b/modules/features2d/test/test_fast.cpp @@ -75,8 +75,8 @@ void CV_FastTest::run( int ) vector keypoints1; vector keypoints2; - FAST(gray1, keypoints1, 30, true, type); - FAST(gray2, keypoints2, (type > 0 ? 30 : 20), true, type); + FASTX(gray1, keypoints1, 30, true, type); + FASTX(gray2, keypoints2, (type > 0 ? 30 : 20), true, type); for(size_t i = 0; i < keypoints1.size(); ++i) { -- 2.7.4