diff --git a/modules/features2d/perf/perf_sift.cpp b/modules/features2d/perf/perf_sift.cpp new file mode 100644 index 0000000000..156ebfe8b8 --- /dev/null +++ b/modules/features2d/perf/perf_sift.cpp @@ -0,0 +1,72 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +#include "perf_precomp.hpp" + +namespace opencv_test { namespace { + +typedef perf::TestBaseWithParam sift; + +#define SIFT_IMAGES \ + "cv/detectors_descriptors_evaluation/images_datasets/leuven/img1.png",\ + "stitching/a3.png" + +PERF_TEST_P(sift, detect, testing::Values(SIFT_IMAGES)) +{ + string filename = getDataPath(GetParam()); + Mat frame = imread(filename, IMREAD_GRAYSCALE); + ASSERT_FALSE(frame.empty()) << "Unable to load source image " << filename; + + Mat mask; + declare.in(frame).time(90); + Ptr detector = SIFT::create(); + vector points; + + PERF_SAMPLE_BEGIN(); + detector->detect(frame, points, mask); + PERF_SAMPLE_END(); + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P(sift, extract, testing::Values(SIFT_IMAGES)) +{ + string filename = getDataPath(GetParam()); + Mat frame = imread(filename, IMREAD_GRAYSCALE); + ASSERT_FALSE(frame.empty()) << "Unable to load source image " << filename; + + Mat mask; + declare.in(frame).time(90); + + Ptr detector = SIFT::create(); + vector points; + Mat descriptors; + detector->detect(frame, points, mask); + + PERF_SAMPLE_BEGIN(); + detector->compute(frame, points, descriptors); + PERF_SAMPLE_END(); + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P(sift, full, testing::Values(SIFT_IMAGES)) +{ + string filename = getDataPath(GetParam()); + Mat frame = imread(filename, IMREAD_GRAYSCALE); + ASSERT_FALSE(frame.empty()) << "Unable to load source image " << filename; + + Mat mask; + declare.in(frame).time(90); + Ptr detector = SIFT::create(); + vector points; + Mat descriptors; + + PERF_SAMPLE_BEGIN(); + detector->detectAndCompute(frame, mask, points, descriptors, false); + PERF_SAMPLE_END(); + + SANITY_CHECK_NOTHING(); +} + +}} // namespace diff --git a/modules/features2d/src/sift.cpp b/modules/features2d/src/sift.cpp index 9e39fde879..e8950e6f08 100644 --- a/modules/features2d/src/sift.cpp +++ b/modules/features2d/src/sift.cpp @@ -123,6 +123,7 @@ protected: Ptr SIFT::create( int _nfeatures, int _nOctaveLayers, double _contrastThreshold, double _edgeThreshold, double _sigma ) { + CV_TRACE_FUNCTION(); return makePtr(_nfeatures, _nOctaveLayers, _contrastThreshold, _edgeThreshold, _sigma); } @@ -186,6 +187,8 @@ unpackOctave(const KeyPoint& kpt, int& octave, int& layer, float& scale) static Mat createInitialImage( const Mat& img, bool doubleImageSize, float sigma ) { + CV_TRACE_FUNCTION(); + Mat gray, gray_fpt; if( img.channels() == 3 || img.channels() == 4 ) { @@ -220,6 +223,8 @@ static Mat createInitialImage( const Mat& img, bool doubleImageSize, float sigma void SIFT_Impl::buildGaussianPyramid( const Mat& base, std::vector& pyr, int nOctaves ) const { + CV_TRACE_FUNCTION(); + std::vector sig(nOctaveLayers + 3); pyr.resize(nOctaves*(nOctaveLayers + 3)); @@ -271,6 +276,8 @@ public: void operator()( const cv::Range& range ) const CV_OVERRIDE { + CV_TRACE_FUNCTION(); + const int begin = range.start; const int end = range.end; @@ -294,6 +301,8 @@ private: void SIFT_Impl::buildDoGPyramid( const std::vector& gpyr, std::vector& dogpyr ) const { + CV_TRACE_FUNCTION(); + int nOctaves = (int)gpyr.size()/(nOctaveLayers + 3); dogpyr.resize( nOctaves*(nOctaveLayers + 2) ); @@ -304,6 +313,8 @@ void SIFT_Impl::buildDoGPyramid( const std::vector& gpyr, std::vector& static float calcOrientationHist( const Mat& img, Point pt, int radius, float sigma, float* hist, int n ) { + CV_TRACE_FUNCTION(); + int i, j, k, len = (radius*2+1)*(radius*2+1); float expf_scale = -1.f/(2.f * sigma * sigma); @@ -442,6 +453,8 @@ static bool adjustLocalExtrema( const std::vector& dog_pyr, KeyPoint& kpt, int& layer, int& r, int& c, int nOctaveLayers, float contrastThreshold, float edgeThreshold, float sigma ) { + CV_TRACE_FUNCTION(); + const float img_scale = 1.f/(255*SIFT_FIXPT_SCALE); const float deriv_scale = img_scale*0.5f; const float second_deriv_scale = img_scale; @@ -574,6 +587,8 @@ public: tls_kpts_struct(_tls_kpts_struct) { } void operator()( const cv::Range& range ) const CV_OVERRIDE { + CV_TRACE_FUNCTION(); + const int begin = range.start; const int end = range.end; @@ -618,6 +633,8 @@ public: val <= prevptr[c-step-1] && val <= prevptr[c-step] && val <= prevptr[c-step+1] && val <= prevptr[c+step-1] && val <= prevptr[c+step] && val <= prevptr[c+step+1]))) { + CV_TRACE_REGION("pixel_candidate"); + int r1 = r, c1 = c, layer = i; if( !adjustLocalExtrema(dog_pyr, kpt, o, layer, r1, c1, nOctaveLayers, (float)contrastThreshold, @@ -670,6 +687,8 @@ private: void SIFT_Impl::findScaleSpaceExtrema( const std::vector& gauss_pyr, const std::vector& dog_pyr, std::vector& keypoints ) const { + CV_TRACE_FUNCTION(); + const int nOctaves = (int)gauss_pyr.size()/(nOctaveLayers + 3); const int threshold = cvFloor(0.5 * contrastThreshold / nOctaveLayers * 255 * SIFT_FIXPT_SCALE); @@ -705,6 +724,8 @@ void SIFT_Impl::findScaleSpaceExtrema( const std::vector& gauss_pyr, const static void calcSIFTDescriptor( const Mat& img, Point2f ptf, float ori, float scl, int d, int n, float* dst ) { + CV_TRACE_FUNCTION(); + Point pt(cvRound(ptf.x), cvRound(ptf.y)); float cos_t = cosf(ori*(float)(CV_PI/180)); float sin_t = sinf(ori*(float)(CV_PI/180)); @@ -1015,6 +1036,8 @@ public: void operator()( const cv::Range& range ) const CV_OVERRIDE { + CV_TRACE_FUNCTION(); + const int begin = range.start; const int end = range.end; @@ -1048,6 +1071,7 @@ private: static void calcDescriptors(const std::vector& gpyr, const std::vector& keypoints, Mat& descriptors, int nOctaveLayers, int firstOctave ) { + CV_TRACE_FUNCTION(); parallel_for_(Range(0, static_cast(keypoints.size())), calcDescriptorsComputer(gpyr, keypoints, descriptors, nOctaveLayers, firstOctave)); } @@ -1081,6 +1105,8 @@ void SIFT_Impl::detectAndCompute(InputArray _image, InputArray _mask, OutputArray _descriptors, bool useProvidedKeypoints) { + CV_TRACE_FUNCTION(); + int firstOctave = -1, actualNOctaves = 0, actualNLayers = 0; Mat image = _image.getMat(), mask = _mask.getMat();