diff --git a/modules/imgproc/src/templmatch.cpp b/modules/imgproc/src/templmatch.cpp index 5e1ad20343..0a3b95d7c7 100644 --- a/modules/imgproc/src/templmatch.cpp +++ b/modules/imgproc/src/templmatch.cpp @@ -346,7 +346,10 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result, } if( numType == 2 ) + { num = wndSum2 - 2*num + templSum2; + num = MAX(num, 0.); + } } if( isNormed )