|
|
@ -43,19 +43,11 @@ |
|
|
|
#include "opencl_kernels.hpp" |
|
|
|
#include "opencl_kernels.hpp" |
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////// matchTemplate //////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////// matchTemplate //////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
namespace cv |
|
|
|
namespace cv |
|
|
|
{ |
|
|
|
{ |
|
|
|
static bool matchTemplate_CCORR(InputArray _image, InputArray _templ, OutputArray _result); |
|
|
|
|
|
|
|
static bool matchTemplate_CCORR_NORMED(InputArray _image, InputArray _templ, OutputArray _result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool matchTemplate_SQDIFF(InputArray _image, InputArray _templ, OutputArray _result); |
|
|
|
|
|
|
|
static bool matchTemplate_SQDIFF_NORMED (InputArray _image, InputArray _templ, OutputArray _result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool matchTemplate_CCOEFF(InputArray _image, InputArray _templ, OutputArray _result); |
|
|
|
|
|
|
|
static bool matchTemplate_CCOEFF_NORMED(InputArray _image, InputArray _templ, OutputArray _result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool matchTemplateNaive_CCORR (InputArray _image, InputArray _templ, OutputArray _result, int cn); |
|
|
|
#ifdef HAVE_OPENCL |
|
|
|
static bool matchTemplateNaive_SQDIFF(InputArray _image, InputArray _templ, OutputArray _result, int cn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool useNaive(int method, int depth, Size size) |
|
|
|
static bool useNaive(int method, int depth, Size size) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -76,14 +68,6 @@ namespace cv |
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////// CCORR //////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////// CCORR //////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
static bool matchTemplate_CCORR(InputArray _image, InputArray _templ, OutputArray _result) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (useNaive(TM_CCORR, _image.depth(), _templ.size()) ) |
|
|
|
|
|
|
|
return matchTemplateNaive_CCORR(_image, _templ, _result, _image.channels()); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool matchTemplateNaive_CCORR (InputArray _image, InputArray _templ, OutputArray _result, int cn) |
|
|
|
static bool matchTemplateNaive_CCORR (InputArray _image, InputArray _templ, OutputArray _result, int cn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int type = _image.type(); |
|
|
|
int type = _image.type(); |
|
|
@ -137,18 +121,16 @@ namespace cv |
|
|
|
return k.args(ocl::KernelArg::ReadOnlyNoSize(image_sqsums), ocl::KernelArg::WriteOnly(result), templ.rows, templ.cols, templ_sqsum).run(2,globalsize,NULL,false); |
|
|
|
return k.args(ocl::KernelArg::ReadOnlyNoSize(image_sqsums), ocl::KernelArg::WriteOnly(result), templ.rows, templ.cols, templ_sqsum).run(2,globalsize,NULL,false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////SQDIFF//////////////////////////////////////////////////////////////
|
|
|
|
static bool matchTemplate_CCORR(InputArray _image, InputArray _templ, OutputArray _result) |
|
|
|
|
|
|
|
|
|
|
|
static bool matchTemplate_SQDIFF(InputArray _image, InputArray _templ, OutputArray _result) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (useNaive(TM_SQDIFF, _image.depth(), _templ.size())) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return matchTemplateNaive_SQDIFF(_image, _templ, _result, _image.channels());; |
|
|
|
if (useNaive(TM_CCORR, _image.depth(), _templ.size()) ) |
|
|
|
} |
|
|
|
return matchTemplateNaive_CCORR(_image, _templ, _result, _image.channels()); |
|
|
|
else |
|
|
|
else |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////// SQDIFF //////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
static bool matchTemplateNaive_SQDIFF(InputArray _image, InputArray _templ, OutputArray _result, int cn) |
|
|
|
static bool matchTemplateNaive_SQDIFF(InputArray _image, InputArray _templ, OutputArray _result, int cn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int type = _image.type(); |
|
|
|
int type = _image.type(); |
|
|
@ -202,6 +184,14 @@ namespace cv |
|
|
|
return k.args(ocl::KernelArg::ReadOnlyNoSize(image_sqsums), ocl::KernelArg::WriteOnly(result), templ.rows, templ.cols, templ_sqsum).run(2,globalsize,NULL,false); |
|
|
|
return k.args(ocl::KernelArg::ReadOnlyNoSize(image_sqsums), ocl::KernelArg::WriteOnly(result), templ.rows, templ.cols, templ_sqsum).run(2,globalsize,NULL,false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool matchTemplate_SQDIFF(InputArray _image, InputArray _templ, OutputArray _result) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (useNaive(TM_SQDIFF, _image.depth(), _templ.size())) |
|
|
|
|
|
|
|
return matchTemplateNaive_SQDIFF(_image, _templ, _result, _image.channels()); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////// CCOEFF /////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////// CCOEFF /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
static bool matchTemplate_CCOEFF(InputArray _image, InputArray _templ, OutputArray _result) |
|
|
|
static bool matchTemplate_CCOEFF(InputArray _image, InputArray _templ, OutputArray _result) |
|
|
@ -370,10 +360,8 @@ namespace cv |
|
|
|
|
|
|
|
|
|
|
|
return caller(_img, _templ, _result); |
|
|
|
return caller(_img, _templ, _result); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace cv |
|
|
|
#endif |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void crossCorr( const Mat& img, const Mat& _templ, Mat& corr, |
|
|
|
void crossCorr( const Mat& img, const Mat& _templ, Mat& corr, |
|
|
|
Size corrsize, int ctype, |
|
|
|
Size corrsize, int ctype, |
|
|
@ -564,9 +552,7 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr, |
|
|
|
void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result, int method ) |
|
|
|
void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result, int method ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CV_Assert( CV_TM_SQDIFF <= method && method <= CV_TM_CCOEFF_NORMED ); |
|
|
|
CV_Assert( CV_TM_SQDIFF <= method && method <= CV_TM_CCOEFF_NORMED ); |
|
|
|
|
|
|
|
|
|
|
|
CV_Assert( (_img.depth() == CV_8U || _img.depth() == CV_32F) && _img.type() == _templ.type() ); |
|
|
|
CV_Assert( (_img.depth() == CV_8U || _img.depth() == CV_32F) && _img.type() == _templ.type() ); |
|
|
|
|
|
|
|
|
|
|
|
CV_Assert(_img.dims() <= 2); |
|
|
|
CV_Assert(_img.dims() <= 2); |
|
|
|
|
|
|
|
|
|
|
|
bool swapNotNeed = (_img.size().height >= _templ.size().height && _img.size().width >= _templ.size().width); |
|
|
|
bool swapNotNeed = (_img.size().height >= _templ.size().height && _img.size().width >= _templ.size().width); |
|
|
@ -575,9 +561,8 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result, |
|
|
|
CV_Assert(_img.size().height <= _templ.size().height && _img.size().width <= _templ.size().width); |
|
|
|
CV_Assert(_img.size().height <= _templ.size().height && _img.size().width <= _templ.size().width); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool use_opencl = ocl::useOpenCL() && _result.isUMat(); |
|
|
|
CV_OCL_RUN(_img.dims() <= 2 && _result.isUMat(), |
|
|
|
if ( use_opencl && (swapNotNeed ? ocl_matchTemplate(_img,_templ,_result,method) : ocl_matchTemplate(_templ,_img,_result,method))) |
|
|
|
(swapNotNeed ? ocl_matchTemplate(_img,_templ,_result,method) : ocl_matchTemplate(_templ,_img,_result,method))) |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int numType = method == CV_TM_CCORR || method == CV_TM_CCORR_NORMED ? 0 : |
|
|
|
int numType = method == CV_TM_CCORR || method == CV_TM_CCORR_NORMED ? 0 : |
|
|
|
method == CV_TM_CCOEFF || method == CV_TM_CCOEFF_NORMED ? 1 : 2; |
|
|
|
method == CV_TM_CCOEFF || method == CV_TM_CCOEFF_NORMED ? 1 : 2; |
|
|
|