diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index f311780ed5..9c67b082b3 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -1397,6 +1397,7 @@ protected: SURF surf; }; +CV_EXPORTS FeatureDetector* createDetector( const string& detectorType ); /****************************************************************************************\ * DescriptorExtractor * @@ -1468,6 +1469,8 @@ protected: SURF surf; }; +DescriptorExtractor* createDescriptorExtractor( const string& descriptorExtractorType ); + /****************************************************************************************\ * Distance * \****************************************************************************************/ @@ -1758,6 +1761,7 @@ void BruteForceMatcher::matchImpl( const Mat& descriptors_1, const Mat } } +DescriptorMatcher* createDescriptorMatcher( const string& descriptorMatcherType ); /****************************************************************************************\ * GenericDescriptorMatch * diff --git a/modules/features2d/src/descriptors.cpp b/modules/features2d/src/descriptors.cpp index ddeb61119e..88aeb06cae 100644 --- a/modules/features2d/src/descriptors.cpp +++ b/modules/features2d/src/descriptors.cpp @@ -42,9 +42,10 @@ #include "precomp.hpp" using namespace std; -using namespace cv; +namespace cv +{ -CV_EXPORTS void cv::drawMatches( const Mat& img1, const Mat& img2, +CV_EXPORTS void drawMatches( const Mat& img1, const Mat& img2, const vector& keypoints1, const vector& keypoints2, const vector& matches, const vector& mask, Mat& outImg, const Scalar& matchColor, const Scalar& singlePointColor, @@ -221,6 +222,45 @@ void SurfDescriptorExtractor::write( FileStorage &fs ) const fs << "extended" << surf.extended; } +DescriptorExtractor* createDescriptorExtractor( const string& descriptorExtractorType ) +{ + DescriptorExtractor* de = 0; + if( !descriptorExtractorType.compare( "SIFT" ) ) + { + de = new SiftDescriptorExtractor/*( double magnification=SIFT::DescriptorParams::GET_DEFAULT_MAGNIFICATION(), + bool isNormalize=true, bool recalculateAngles=true, + int nOctaves=SIFT::CommonParams::DEFAULT_NOCTAVES, + int nOctaveLayers=SIFT::CommonParams::DEFAULT_NOCTAVE_LAYERS, + int firstOctave=SIFT::CommonParams::DEFAULT_FIRST_OCTAVE, + int angleMode=SIFT::CommonParams::FIRST_ANGLE )*/; + } + else if( !descriptorExtractorType.compare( "SURF" ) ) + { + de = new SurfDescriptorExtractor/*( int nOctaves=4, int nOctaveLayers=2, bool extended=false )*/; + } + else + { + //CV_Error( CV_StsBadArg, "unsupported descriptor extractor type"); + } + return de; +} + +DescriptorMatcher* createDescriptorMatcher( const string& descriptorMatcherType ) +{ + DescriptorMatcher* dm = 0; + if( !descriptorMatcherType.compare( "BruteForce" ) ) + { + dm = new BruteForceMatcher >(); + } + else + { + //CV_Error( CV_StsBadArg, "unsupported descriptor matcher type"); + } + + return dm; +} + + /****************************************************************************************\ * GenericDescriptorMatch * \****************************************************************************************/ @@ -764,3 +804,5 @@ void FernDescriptorMatch::clear () GenericDescriptorMatch::clear(); classifier.release(); } + +} diff --git a/modules/features2d/src/detectors.cpp b/modules/features2d/src/detectors.cpp index 7f0178eb1c..dbf91a6f31 100644 --- a/modules/features2d/src/detectors.cpp +++ b/modules/features2d/src/detectors.cpp @@ -42,8 +42,9 @@ #include "precomp.hpp" using namespace std; -using namespace cv; +namespace cv +{ /* FeatureDetector */ @@ -314,3 +315,44 @@ void SurfFeatureDetector::detectImpl( const Mat& image, const Mat& mask, { surf(image, mask, keypoints); } + +FeatureDetector* createDetector( const string& detectorType ) +{ + FeatureDetector* fd = 0; + if( !detectorType.compare( "FAST" ) ) + { + fd = new FastFeatureDetector( 10/*threshold*/, true/*nonmax_suppression*/ ); + } + else if( !detectorType.compare( "STAR" ) ) + { + fd = new StarFeatureDetector( 16/*max_size*/, 5/*response_threshold*/, 10/*line_threshold_projected*/, + 8/*line_threshold_binarized*/, 5/*suppress_nonmax_size*/ ); + } + else if( !detectorType.compare( "SIFT" ) ) + { + fd = new SiftFeatureDetector(SIFT::DetectorParams::GET_DEFAULT_THRESHOLD(), + SIFT::DetectorParams::GET_DEFAULT_EDGE_THRESHOLD()); + } + else if( !detectorType.compare( "SURF" ) ) + { + fd = new SurfFeatureDetector( 100./*hessian_threshold*/, 3 /*octaves*/, 4/*octave_layers*/ ); + } + else if( !detectorType.compare( "MSER" ) ) + { + fd = new MserFeatureDetector( 5/*delta*/, 60/*min_area*/, 14400/*_max_area*/, 0.25f/*max_variation*/, + 0.2/*min_diversity*/, 200/*max_evolution*/, 1.01/*area_threshold*/, 0.003/*min_margin*/, + 5/*edge_blur_size*/ ); + } + else if( !detectorType.compare( "GFTT" ) ) + { + fd = new GoodFeaturesToTrackDetector( 1000/*maxCorners*/, 0.01/*qualityLevel*/, 1./*minDistance*/, + 3/*int _blockSize*/, true/*useHarrisDetector*/, 0.04/*k*/ ); + } + else + { + //CV_Error( CV_StsBadArg, "unsupported feature detector type"); + } + return fd; +} + +} diff --git a/samples/cpp/descriptor_extractor_matcher.cpp b/samples/cpp/descriptor_extractor_matcher.cpp index c73d15f541..a2f5a299ec 100644 --- a/samples/cpp/descriptor_extractor_matcher.cpp +++ b/samples/cpp/descriptor_extractor_matcher.cpp @@ -1,5 +1,8 @@ -#include +//#include #include +#include "opencv2/core/core.hpp" +#include "opencv2/calib3d/calib3d.hpp" +#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/features2d/features2d.hpp" #include @@ -34,83 +37,6 @@ void warpPerspectiveRand( const Mat& src, Mat& dst, Mat& H, RNG* rng ) warpPerspective( src, dst, H, src.size() ); } -FeatureDetector* createDetector( const string& detectorType ) -{ - FeatureDetector* fd = 0; - if( !detectorType.compare( "FAST" ) ) - { - fd = new FastFeatureDetector( 10/*threshold*/, true/*nonmax_suppression*/ ); - } - else if( !detectorType.compare( "STAR" ) ) - { - fd = new StarFeatureDetector( 16/*max_size*/, 5/*response_threshold*/, 10/*line_threshold_projected*/, - 8/*line_threshold_binarized*/, 5/*suppress_nonmax_size*/ ); - } - else if( !detectorType.compare( "SIFT" ) ) - { - fd = new SiftFeatureDetector(SIFT::DetectorParams::GET_DEFAULT_THRESHOLD(), - SIFT::DetectorParams::GET_DEFAULT_EDGE_THRESHOLD()); - } - else if( !detectorType.compare( "SURF" ) ) - { - fd = new SurfFeatureDetector( 100./*hessian_threshold*/, 3 /*octaves*/, 4/*octave_layers*/ ); - } - else if( !detectorType.compare( "MSER" ) ) - { - fd = new MserFeatureDetector( 5/*delta*/, 60/*min_area*/, 14400/*_max_area*/, 0.25f/*max_variation*/, - 0.2/*min_diversity*/, 200/*max_evolution*/, 1.01/*area_threshold*/, 0.003/*min_margin*/, - 5/*edge_blur_size*/ ); - } - else if( !detectorType.compare( "GFTT" ) ) - { - fd = new GoodFeaturesToTrackDetector( 1000/*maxCorners*/, 0.01/*qualityLevel*/, 1./*minDistance*/, - 3/*int _blockSize*/, true/*useHarrisDetector*/, 0.04/*k*/ ); - } - else - { - //CV_Error( CV_StsBadArg, "unsupported feature detector type"); - } - return fd; -} - -DescriptorExtractor* createDescriptorExtractor( const string& descriptorExtractorType ) -{ - DescriptorExtractor* de = 0; - if( !descriptorExtractorType.compare( "SIFT" ) ) - { - de = new SiftDescriptorExtractor/*( double magnification=SIFT::DescriptorParams::GET_DEFAULT_MAGNIFICATION(), - bool isNormalize=true, bool recalculateAngles=true, - int nOctaves=SIFT::CommonParams::DEFAULT_NOCTAVES, - int nOctaveLayers=SIFT::CommonParams::DEFAULT_NOCTAVE_LAYERS, - int firstOctave=SIFT::CommonParams::DEFAULT_FIRST_OCTAVE, - int angleMode=SIFT::CommonParams::FIRST_ANGLE )*/; - } - else if( !descriptorExtractorType.compare( "SURF" ) ) - { - de = new SurfDescriptorExtractor/*( int nOctaves=4, int nOctaveLayers=2, bool extended=false )*/; - } - else - { - //CV_Error( CV_StsBadArg, "unsupported descriptor extractor type"); - } - return de; -} - -DescriptorMatcher* createDescriptorMatcher( const string& descriptorMatcherType ) -{ - DescriptorMatcher* dm = 0; - if( !descriptorMatcherType.compare( "BruteForce" ) ) - { - dm = new BruteForceMatcher >(); - } - else - { - //CV_Error( CV_StsBadArg, "unsupported descriptor matcher type"); - } - - return dm; -} - const string winName = "correspondences"; void doIteration( const Mat& img1, Mat& img2, bool isWarpPerspective,