From: Vadim Pisarevsky Date: Fri, 22 Jun 2012 13:34:03 +0000 (+0000) Subject: added the optional output maxima value to phaseCorrelate (patch #2071 by Robert Huitl) X-Git-Tag: accepted/2.0/20130307.220821~364^2~568 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0c65ea976a85663331cf507a049dc6e095a77c85;p=profile%2Fivi%2Fopencv.git added the optional output maxima value to phaseCorrelate (patch #2071 by Robert Huitl) --- diff --git a/modules/imgproc/doc/motion_analysis_and_object_tracking.rst b/modules/imgproc/doc/motion_analysis_and_object_tracking.rst index 8a4d050..8083481 100644 --- a/modules/imgproc/doc/motion_analysis_and_object_tracking.rst +++ b/modules/imgproc/doc/motion_analysis_and_object_tracking.rst @@ -151,11 +151,12 @@ The function is used to detect translational shifts that occur between two image Calculates the cross-power spectrum of two supplied source arrays. The arrays are padded if needed with :ocv:func:`getOptimalDFTSize`. -.. ocv:function:: Point2d phaseCorrelate(InputArray src1, InputArray src2, InputArray window = noArray()) +.. ocv:function:: Point2d phaseCorrelate(InputArray src1, InputArray src2, InputArray window = noArray(), double* response = 0) :param src1: Source floating point array (CV_32FC1 or CV_64FC1) :param src2: Source floating point array (CV_32FC1 or CV_64FC1) :param window: Floating point array with windowing coefficients to reduce edge effects (optional). + :param response: Signal power within the 5x5 centroid around the peak, between 0 and 1 (optional). Return value: detected phase shift (sub-pixel) between the two arrays. @@ -190,6 +191,8 @@ The function performs the following equations (\Delta x, \Delta y) = \texttt{weightedCentroid} \{\arg \max_{(x, y)}\{r\}\} +* If non-zero, the response parameter is computed as the sum of the elements of r within the 5x5 centroid around the peak location. It is normalized to a maximum of 1 (meaning there is a single peak) and will be smaller when there are multiple peaks. + .. seealso:: :ocv:func:`dft`, :ocv:func:`getOptimalDFTSize`, diff --git a/modules/imgproc/include/opencv2/imgproc/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc/imgproc.hpp index 9bbcde4..f0a9172 100644 --- a/modules/imgproc/include/opencv2/imgproc/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc/imgproc.hpp @@ -600,7 +600,8 @@ CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst, //! computes PSNR image/video quality metric CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2); -CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2, InputArray window = noArray()); +CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2, + InputArray window = noArray(), CV_OUT double* response=0); CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type); //! type of the threshold operation diff --git a/modules/imgproc/src/phasecorr.cpp b/modules/imgproc/src/phasecorr.cpp index 71582cb..3b6c2eb 100644 --- a/modules/imgproc/src/phasecorr.cpp +++ b/modules/imgproc/src/phasecorr.cpp @@ -406,7 +406,7 @@ static void fftShift(InputOutputArray _out) merge(planes, out); } -static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weightBoxSize) +static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Size weightBoxSize, double* response) { Mat src = _src.getMat(); @@ -475,6 +475,9 @@ static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Siz } } + if(response) + *response = sumIntensity; + sumIntensity += DBL_EPSILON; // prevent div0 problems... centroid.x /= sumIntensity; @@ -485,7 +488,7 @@ static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Siz } -cv::Point2d cv::phaseCorrelate(InputArray _src1, InputArray _src2, InputArray _window) +cv::Point2d cv::phaseCorrelate(InputArray _src1, InputArray _src2, InputArray _window, double* response) { Mat src1 = _src1.getMat(); Mat src2 = _src2.getMat(); @@ -553,7 +556,11 @@ cv::Point2d cv::phaseCorrelate(InputArray _src1, InputArray _src2, InputArray _w // get the phase shift with sub-pixel accuracy, 5x5 window seems about right here... Point2d t; - t = weightedCentroid(C, peakLoc, Size(5, 5)); + t = weightedCentroid(C, peakLoc, Size(5, 5), response); + + // max response is M*N (not exactly, might be slightly larger due to rounding errors) + if(response) + *response /= M*N; // adjust shift relative to image center... Point2d center((double)padded1.cols / 2.0, (double)padded1.rows / 2.0);