Bugfix for an overlapping size of image and template for matchTemplate.
authorHeinz Hofbauer <Hofbauer.Heinz@gmx.net>
Wed, 3 Jul 2013 12:58:40 +0000 (14:58 +0200)
committerHeinz Hofbauer <Hofbauer.Heinz@gmx.net>
Wed, 3 Jul 2013 12:58:40 +0000 (14:58 +0200)
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

index ec7a92a..18d7da9 100644 (file)
@@ -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();