Commit 5a730d09 authored by Andrey Kamaev's avatar Andrey Kamaev

Fix binary compatibility of opencv_features2d

parent 88e9a072
...@@ -566,19 +566,19 @@ protected: ...@@ -566,19 +566,19 @@ protected:
CV_EXPORTS void FAST( InputArray image, CV_OUT vector<KeyPoint>& keypoints, CV_EXPORTS void FAST( InputArray image, CV_OUT vector<KeyPoint>& keypoints,
int threshold, bool nonmaxSupression=true ); int threshold, bool nonmaxSupression=true );
CV_EXPORTS void FAST( InputArray image, CV_OUT vector<KeyPoint>& keypoints, CV_EXPORTS void FASTX( InputArray image, CV_OUT vector<KeyPoint>& keypoints,
int threshold, bool nonmaxSupression, int type ); int threshold, bool nonmaxSupression, int type );
class CV_EXPORTS_W FastFeatureDetector : public FeatureDetector class CV_EXPORTS_W FastFeatureDetector : public FeatureDetector
{ {
public: public:
enum enum
{ { // Define it in old class to simplify migration to 2.5
TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2 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=10, bool nonmaxSuppression=true );
CV_WRAP FastFeatureDetector( int threshold, bool nonmaxSuppression, int type);
AlgorithmInfo* info() const; AlgorithmInfo* info() const;
protected: protected:
...@@ -586,7 +586,6 @@ protected: ...@@ -586,7 +586,6 @@ protected:
int threshold; int threshold;
bool nonmaxSuppression; bool nonmaxSuppression;
short type;
}; };
......
...@@ -30,10 +30,13 @@ PERF_TEST_P(fast, detect, testing::Combine( ...@@ -30,10 +30,13 @@ PERF_TEST_P(fast, detect, testing::Combine(
declare.in(frame); declare.in(frame);
FastFeatureDetector fd(20, true, type); Ptr<FeatureDetector> fd = Algorithm::create<FeatureDetector>("Feature2D.FASTX");
fd->set("threshold", 20);
fd->set("nonmaxSuppression", true);
fd->set("type", type);
vector<KeyPoint> points; vector<KeyPoint> points;
TEST_CYCLE() fd.detect(frame, points); TEST_CYCLE() fd->detect(frame, points);
SANITY_CHECK_KEYPOINTS(points); SANITY_CHECK_KEYPOINTS(points);
} }
......
...@@ -121,7 +121,7 @@ private: ...@@ -121,7 +121,7 @@ private:
float scale_; float scale_;
float offset_; float offset_;
// agast // agast
cv::Ptr<cv::FastFeatureDetector> fast_9_16_; cv::Ptr<cv::FastFeatureDetector2> fast_9_16_;
int pixel_5_8_[25]; int pixel_5_8_[25];
int pixel_9_16_[25]; int pixel_9_16_[25];
}; };
...@@ -2000,7 +2000,7 @@ BriskLayer::BriskLayer(const cv::Mat& img_in, float scale_in, float offset_in) ...@@ -2000,7 +2000,7 @@ BriskLayer::BriskLayer(const cv::Mat& img_in, float scale_in, float offset_in)
scale_ = scale_in; scale_ = scale_in;
offset_ = offset_in; offset_ = offset_in;
// create an agast detector // 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_5_8_, (int)img_.step, 8);
makeOffsets(pixel_9_16_, (int)img_.step, 16); makeOffsets(pixel_9_16_, (int)img_.step, 16);
} }
...@@ -2022,7 +2022,7 @@ BriskLayer::BriskLayer(const BriskLayer& layer, int mode) ...@@ -2022,7 +2022,7 @@ BriskLayer::BriskLayer(const BriskLayer& layer, int mode)
offset_ = 0.5f * scale_ - 0.5f; offset_ = 0.5f * scale_ - 0.5f;
} }
scores_ = cv::Mat::zeros(img_.rows, img_.cols, CV_8U); 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_5_8_, (int)img_.step, 8);
makeOffsets(pixel_9_16_, (int)img_.step, 16); makeOffsets(pixel_9_16_, (int)img_.step, 16);
} }
......
...@@ -245,7 +245,7 @@ void FAST_t(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bo ...@@ -245,7 +245,7 @@ void FAST_t(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bo
} }
} }
void FAST(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bool nonmax_suppression, int type) void FASTX(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bool nonmax_suppression, int type)
{ {
switch(type) { switch(type) {
case FastFeatureDetector::TYPE_5_8: case FastFeatureDetector::TYPE_5_8:
...@@ -262,24 +262,37 @@ void FAST(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bool ...@@ -262,24 +262,37 @@ void FAST(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bool
void FAST(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bool nonmax_suppression) void FAST(InputArray _img, std::vector<KeyPoint>& 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::FastFeatureDetector( int _threshold, bool _nonmaxSuppression ) 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 ) FastFeatureDetector2::FastFeatureDetector2( int _threshold, bool _nonmaxSuppression, int _type )
: threshold(_threshold), nonmaxSuppression(_nonmaxSuppression), type((short)_type) : FastFeatureDetector(_threshold, _nonmaxSuppression), type((short)_type)
{} {}
void FastFeatureDetector::detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask ) const void FastFeatureDetector::detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask ) const
{ {
Mat grayImage = image; Mat grayImage = image;
if( image.type() != CV_8U ) cvtColor( image, grayImage, CV_BGR2GRAY ); 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<KeyPoint>& 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 ); KeyPointsFilter::runByPixelsMask( keypoints, mask );
} }
......
...@@ -56,6 +56,19 @@ void makeOffsets(int pixel[25], int row_stride, int patternSize); ...@@ -56,6 +56,19 @@ void makeOffsets(int pixel[25], int row_stride, int patternSize);
template<int patternSize> template<int patternSize>
int cornerScore(const uchar* ptr, const int pixel[], int threshold); 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<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
short type;
};
} }
#endif #endif
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
//M*/ //M*/
#include "precomp.hpp" #include "precomp.hpp"
#include "fast_score.hpp"
using namespace cv; using namespace cv;
...@@ -68,6 +69,10 @@ CV_INIT_ALGORITHM(BriefDescriptorExtractor, "Feature2D.BRIEF", ...@@ -68,6 +69,10 @@ CV_INIT_ALGORITHM(BriefDescriptorExtractor, "Feature2D.BRIEF",
/////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
CV_INIT_ALGORITHM(FastFeatureDetector, "Feature2D.FAST", 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, "threshold", obj.threshold);
obj.info()->addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression); obj.info()->addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression);
obj.info()->addParam(obj, "type", obj.type)); obj.info()->addParam(obj, "type", obj.type));
...@@ -167,6 +172,7 @@ bool cv::initModule_features2d(void) ...@@ -167,6 +172,7 @@ bool cv::initModule_features2d(void)
all &= !BriefDescriptorExtractor_info_auto.name().empty(); all &= !BriefDescriptorExtractor_info_auto.name().empty();
all &= !BRISK_info_auto.name().empty(); all &= !BRISK_info_auto.name().empty();
all &= !FastFeatureDetector_info_auto.name().empty(); all &= !FastFeatureDetector_info_auto.name().empty();
all &= !FastFeatureDetector2_info_auto.name().empty();
all &= !StarDetector_info_auto.name().empty(); all &= !StarDetector_info_auto.name().empty();
all &= !MSER_info_auto.name().empty(); all &= !MSER_info_auto.name().empty();
all &= !FREAK_info_auto.name().empty(); all &= !FREAK_info_auto.name().empty();
......
...@@ -75,8 +75,8 @@ void CV_FastTest::run( int ) ...@@ -75,8 +75,8 @@ void CV_FastTest::run( int )
vector<KeyPoint> keypoints1; vector<KeyPoint> keypoints1;
vector<KeyPoint> keypoints2; vector<KeyPoint> keypoints2;
FAST(gray1, keypoints1, 30, true, type); FASTX(gray1, keypoints1, 30, true, type);
FAST(gray2, keypoints2, (type > 0 ? 30 : 20), true, type); FASTX(gray2, keypoints2, (type > 0 ? 30 : 20), true, type);
for(size_t i = 0; i < keypoints1.size(); ++i) for(size_t i = 0; i < keypoints1.size(); ++i)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment