From 35457afab38553c234f544ed680d2890492016d1 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev <no@email> Date: Wed, 30 Nov 2011 15:57:41 +0000 Subject: [PATCH] Fixed bug in phaseCorrelate --- modules/imgproc/src/phasecorr.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/imgproc/src/phasecorr.cpp b/modules/imgproc/src/phasecorr.cpp index 8d2b5db675..70f2d8f9b6 100644 --- a/modules/imgproc/src/phasecorr.cpp +++ b/modules/imgproc/src/phasecorr.cpp @@ -53,6 +53,7 @@ static void magSpectrums( InputArray _src, OutputArray _dst) _dst.create( src.rows, src.cols, CV_64FC1 ); Mat dst = _dst.getMat(); + dst.setTo(0);//Mat elements are not equal to zero by default! bool is_1d = (rows == 1 || (cols == 1 && src.isContinuous() && dst.isContinuous())); @@ -547,10 +548,11 @@ void cv::createHanningWindow(OutputArray _dst, cv::Size winSize, int type) int rows = dst.rows; int cols = dst.cols; + int step = dst.step/dst.elemSize1(); if(dst.depth() == CV_32F) { - float* dstData = (float*)dst.data; + float* dstData = dst.ptr<float>(); for(int i = 0; i < rows; i++) { @@ -558,16 +560,13 @@ void cv::createHanningWindow(OutputArray _dst, cv::Size winSize, int type) for(int j = 0; j < cols; j++) { double wc = 0.5 * (1.0f - cos(2.0f * CV_PI * (double)j / (double)(cols - 1))); - dstData[i*cols + j] = (float)(wr * wc); + dstData[i*step + j] = (float)(wr * wc); } } - - // perform batch sqrt for SSE performance gains - cv::sqrt(dst, dst); } else { - double* dstData = (double*)dst.data; + double* dstData = dst.ptr<double>(); for(int i = 0; i < rows; i++) { @@ -575,11 +574,11 @@ void cv::createHanningWindow(OutputArray _dst, cv::Size winSize, int type) for(int j = 0; j < cols; j++) { double wc = 0.5 * (1.0 - cos(2.0 * CV_PI * (double)j / (double)(cols - 1))); - dstData[i*cols + j] = wr * wc; + dstData[i*step + j] = wr * wc; } } - - // perform batch sqrt for SSE performance gains - cv::sqrt(dst, dst); } + + // perform batch sqrt for SSE performance gains + cv::sqrt(dst, dst); }