From a26c4fa2a2bc974f8f8bdd902dce56fc8d0944aa Mon Sep 17 00:00:00 2001 From: Heinz Hofbauer Date: Wed, 3 Jul 2013 14:58:40 +0200 Subject: [PATCH] Bugfix for an overlapping size of image and template for matchTemplate. Example: img of size 10x10 and templ of size 11x9. In subsequent code this will results in either width or height of corrSize to be zero (0). Line 261 will call crossCorr which will then have a zero size of either blocksize.width or blocksize.height resulting in a division by zero crach in lines 137 or 138. --- modules/imgproc/src/templmatch.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/imgproc/src/templmatch.cpp b/modules/imgproc/src/templmatch.cpp index ec7a92a22..18d7da9d9 100644 --- a/modules/imgproc/src/templmatch.cpp +++ b/modules/imgproc/src/templmatch.cpp @@ -248,6 +248,8 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result, CV_Assert( (img.depth() == CV_8U || img.depth() == CV_32F) && img.type() == templ.type() ); + CV_Assert( img.rows >= templ.rows && img.cols >= templ.cols); + Size corrSize(img.cols - templ.cols + 1, img.rows - templ.rows + 1); _result.create(corrSize, CV_32F); Mat result = _result.getMat();