Merge pull request #12916 from lqy123000:bugfix_templmatch

* avoid rounding errors

* imgproc: replace condition in matchTemplate
pull/13059/head^2
lqy123000 6 years ago committed by Alexander Alekhin
parent d9d8ad20a0
commit cceeca3052
  1. 7
      modules/imgproc/src/templmatch.cpp

@ -947,7 +947,12 @@ static void common_matchTemplate( Mat& img, Mat& templ, Mat& result, int method,
if( isNormed ) if( isNormed )
{ {
t = std::sqrt(MAX(wndSum2 - wndMean2,0))*templNorm; double diff2 = MAX(wndSum2 - wndMean2, 0);
if (diff2 <= std::min(0.5, 10 * FLT_EPSILON * wndSum2))
t = 0; // avoid rounding errors
else
t = std::sqrt(diff2)*templNorm;
if( fabs(num) < t ) if( fabs(num) < t )
num /= t; num /= t;
else if( fabs(num) < t*1.125 ) else if( fabs(num) < t*1.125 )

Loading…
Cancel
Save