From 0ebb3ab0ea65b8565e5a84d609258d7a573b787a Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 28 Jan 2014 23:10:43 +0400 Subject: [PATCH] optimized createHanningWindow --- modules/imgproc/perf/perf_phasecorr.cpp | 22 ++++++++++++++++++++++ modules/imgproc/src/phasecorr.cpp | 24 ++++++++++++------------ 2 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 modules/imgproc/perf/perf_phasecorr.cpp diff --git a/modules/imgproc/perf/perf_phasecorr.cpp b/modules/imgproc/perf/perf_phasecorr.cpp new file mode 100644 index 000000000..ee9d94e31 --- /dev/null +++ b/modules/imgproc/perf/perf_phasecorr.cpp @@ -0,0 +1,22 @@ +#include "perf_precomp.hpp" + +using namespace std; +using namespace cv; +using namespace perf; +using namespace testing; +using std::tr1::make_tuple; +using std::tr1::get; + +typedef TestBaseWithParam CreateHanningWindowFixture; + +PERF_TEST_P( CreateHanningWindowFixture, CreateHanningWindow, Values(szVGA, sz1080p)) +{ + const Size size = GetParam(); + Mat dst(size, CV_32FC1); + + declare.in(dst, WARMUP_RNG).out(dst); + + TEST_CYCLE() cv::createHanningWindow(dst, size, CV_32FC1); + + SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); +} diff --git a/modules/imgproc/src/phasecorr.cpp b/modules/imgproc/src/phasecorr.cpp index d21a4938f..f513e84e2 100644 --- a/modules/imgproc/src/phasecorr.cpp +++ b/modules/imgproc/src/phasecorr.cpp @@ -576,20 +576,23 @@ void cv::createHanningWindow(OutputArray _dst, cv::Size winSize, int type) _dst.create(winSize, type); Mat dst = _dst.getMat(); - int rows = dst.rows; - int cols = dst.cols; + int rows = dst.rows, cols = dst.cols; + + AutoBuffer _wc(cols); + double * const wc = (double *)_wc; + + double coeff0 = 2.0 * CV_PI / (double)(cols - 1), coeff1 = 2.0f * CV_PI / (double)(rows - 1); + for(int j = 0; j < cols; j++) + wc[j] = 0.5 * (1.0 - cos(coeff0 * j)); if(dst.depth() == CV_32F) { for(int i = 0; i < rows; i++) { float* dstData = dst.ptr(i); - double wr = 0.5 * (1.0f - cos(2.0f * CV_PI * (double)i / (double)(rows - 1))); + double wr = 0.5 * (1.0 - cos(coeff1 * i)); for(int j = 0; j < cols; j++) - { - double wc = 0.5 * (1.0f - cos(2.0f * CV_PI * (double)j / (double)(cols - 1))); - dstData[j] = (float)(wr * wc); - } + dstData[j] = (float)(wr * wc[j]); } } else @@ -597,12 +600,9 @@ void cv::createHanningWindow(OutputArray _dst, cv::Size winSize, int type) for(int i = 0; i < rows; i++) { double* dstData = dst.ptr(i); - double wr = 0.5 * (1.0 - cos(2.0 * CV_PI * (double)i / (double)(rows - 1))); + double wr = 0.5 * (1.0 - cos(coeff1 * i)); for(int j = 0; j < cols; j++) - { - double wc = 0.5 * (1.0 - cos(2.0 * CV_PI * (double)j / (double)(cols - 1))); - dstData[j] = wr * wc; - } + dstData[j] = wr * wc[j]; } }