@ -564,7 +564,6 @@ static bool ocl_matchTemplate( InputArray _img, InputArray _templ, OutputArray _
# include "opencv2/core/hal/hal.hpp"
# include "opencv2/core/hal/hal.hpp"
void crossCorr ( const Mat & img , const Mat & _templ , Mat & corr ,
void crossCorr ( const Mat & img , const Mat & _templ , Mat & corr ,
Size corrsize , int ctype ,
Point anchor , double delta , int borderType )
Point anchor , double delta , int borderType )
{
{
const double blockScale = 4.5 ;
const double blockScale = 4.5 ;
@ -574,7 +573,7 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
Mat templ = _templ ;
Mat templ = _templ ;
int depth = img . depth ( ) , cn = img . channels ( ) ;
int depth = img . depth ( ) , cn = img . channels ( ) ;
int tdepth = templ . depth ( ) , tcn = templ . channels ( ) ;
int tdepth = templ . depth ( ) , tcn = templ . channels ( ) ;
int cdepth = CV_MAT_DEPTH ( ctype ) , ccn = CV_MAT_CN ( ctype ) ;
int cdepth = corr . depth ( ) , ccn = corr . channels ( ) ;
CV_Assert ( img . dims < = 2 & & templ . dims < = 2 & & corr . dims < = 2 ) ;
CV_Assert ( img . dims < = 2 & & templ . dims < = 2 & & corr . dims < = 2 ) ;
@ -585,13 +584,11 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
}
}
CV_Assert ( depth = = tdepth | | tdepth = = CV_32F ) ;
CV_Assert ( depth = = tdepth | | tdepth = = CV_32F ) ;
CV_Assert ( corrsize . height < = img . rows + templ . rows - 1 & &
CV_Assert ( corr . rows < = img . rows + templ . rows - 1 & &
corrsize . width < = img . cols + templ . cols - 1 ) ;
corr . cols < = img . cols + templ . cols - 1 ) ;
CV_Assert ( ccn = = 1 | | delta = = 0 ) ;
CV_Assert ( ccn = = 1 | | delta = = 0 ) ;
corr . create ( corrsize , ctype ) ;
int maxDepth = depth > CV_8S ? CV_64F : std : : max ( std : : max ( CV_32F , tdepth ) , cdepth ) ;
int maxDepth = depth > CV_8S ? CV_64F : std : : max ( std : : max ( CV_32F , tdepth ) , cdepth ) ;
Size blocksize , dftsize ;
Size blocksize , dftsize ;
@ -815,8 +812,8 @@ static void matchTemplateMask( InputArray _img, InputArray _templ, OutputArray _
Mat mask2_templ = templ . mul ( mask2 ) ;
Mat mask2_templ = templ . mul ( mask2 ) ;
Mat corr ( corrSize , CV_32F ) ;
Mat corr ( corrSize , CV_32F ) ;
crossCorr ( img , mask2_templ , corr , corr . size ( ) , corr . type ( ) , Point ( 0 , 0 ) , 0 , 0 ) ;
crossCorr ( img , mask2_templ , corr , Point ( 0 , 0 ) , 0 , 0 ) ;
crossCorr ( img2 , mask , result , result . size ( ) , result . type ( ) , Point ( 0 , 0 ) , 0 , 0 ) ;
crossCorr ( img2 , mask , result , Point ( 0 , 0 ) , 0 , 0 ) ;
result - = corr * 2 ;
result - = corr * 2 ;
result + = templSum2 ;
result + = templSum2 ;
@ -830,8 +827,8 @@ static void matchTemplateMask( InputArray _img, InputArray _templ, OutputArray _
}
}
Mat corr ( corrSize , CV_32F ) ;
Mat corr ( corrSize , CV_32F ) ;
crossCorr ( img2 , mask2 , corr , corr . size ( ) , corr . type ( ) , Point ( 0 , 0 ) , 0 , 0 ) ;
crossCorr ( img2 , mask2 , corr , Point ( 0 , 0 ) , 0 , 0 ) ;
crossCorr ( img , mask_templ , result , result . size ( ) , result . type ( ) , Point ( 0 , 0 ) , 0 , 0 ) ;
crossCorr ( img , mask_templ , result , Point ( 0 , 0 ) , 0 , 0 ) ;
sqrt ( corr , corr ) ;
sqrt ( corr , corr ) ;
result = result . mul ( 1 / corr ) ;
result = result . mul ( 1 / corr ) ;
@ -1130,7 +1127,7 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result,
CV_IPP_RUN_FAST ( ipp_matchTemplate ( img , templ , result , method ) )
CV_IPP_RUN_FAST ( ipp_matchTemplate ( img , templ , result , method ) )
crossCorr ( img , templ , result , result . size ( ) , result . type ( ) , Point ( 0 , 0 ) , 0 , 0 ) ;
crossCorr ( img , templ , result , Point ( 0 , 0 ) , 0 , 0 ) ;
common_matchTemplate ( img , templ , result , method , cn ) ;
common_matchTemplate ( img , templ , result , method , cn ) ;
}
}