Skip to content

Commit 6bfbcf0

Browse files
Andrey PavlenkoOpenCV Buildbot
Andrey Pavlenko
authored and
OpenCV Buildbot
committed
Merge pull request opencv#2587 from ElenaGvozdeva:ipp_matchTemplate
2 parents f7f4593 + 43c29a6 commit 6bfbcf0

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

modules/imgproc/src/templmatch.cpp

+88
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,93 @@ static bool ocl_matchTemplate( InputArray _img, InputArray _templ, OutputArray _
341341

342342
#endif
343343

344+
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
345+
346+
typedef IppStatus (CV_STDCALL * ippimatchTemplate)(const void*, int, IppiSize, const void*, int, IppiSize, Ipp32f* , int , IppEnum , Ipp8u*);
347+
348+
static bool ipp_crossCorr(const Mat& src, const Mat& tpl, Mat& dst)
349+
{
350+
if (src.channels()!= 1)
351+
return false;
352+
353+
IppStatus status;
354+
355+
IppiSize srcRoiSize = {src.cols,src.rows};
356+
IppiSize tplRoiSize = {tpl.cols,tpl.rows};
357+
358+
Ipp8u *pBuffer;
359+
int bufSize=0;
360+
361+
int depth = src.depth();
362+
363+
ippimatchTemplate ippFunc =
364+
depth==CV_8U ? (ippimatchTemplate)ippiCrossCorrNorm_8u32f_C1R:
365+
depth==CV_32F? (ippimatchTemplate)ippiCrossCorrNorm_32f_C1R: 0;
366+
367+
if (ippFunc==0)
368+
return false;
369+
370+
IppEnum funCfg = (IppEnum)(ippAlgAuto | ippiNormNone | ippiROIValid);
371+
372+
status = ippiCrossCorrNormGetBufferSize(srcRoiSize, tplRoiSize, funCfg, &bufSize);
373+
if ( status < 0 )
374+
return false;
375+
376+
pBuffer = ippsMalloc_8u( bufSize );
377+
378+
status = ippFunc(src.data, (int)src.step, srcRoiSize, tpl.data, (int)tpl.step, tplRoiSize, (Ipp32f*)dst.data, (int)dst.step, funCfg, pBuffer);
379+
380+
ippsFree( pBuffer );
381+
return status >= 0;
382+
}
383+
384+
static bool ipp_sqrDistance(const Mat& src, const Mat& tpl, Mat& dst)
385+
{
386+
if (src.channels()!= 1)
387+
return false;
388+
389+
IppStatus status;
390+
391+
IppiSize srcRoiSize = {src.cols,src.rows};
392+
IppiSize tplRoiSize = {tpl.cols,tpl.rows};
393+
394+
Ipp8u *pBuffer;
395+
int bufSize=0;
396+
397+
int depth = src.depth();
398+
399+
ippimatchTemplate ippFunc =
400+
depth==CV_8U ? (ippimatchTemplate)ippiSqrDistanceNorm_8u32f_C1R:
401+
depth==CV_32F? (ippimatchTemplate)ippiSqrDistanceNorm_32f_C1R: 0;
402+
403+
if (ippFunc==0)
404+
return false;
405+
406+
IppEnum funCfg = (IppEnum)(ippAlgAuto | ippiNormNone | ippiROIValid);
407+
408+
status = ippiSqrDistanceNormGetBufferSize(srcRoiSize, tplRoiSize, funCfg, &bufSize);
409+
if ( status < 0 )
410+
return false;
411+
412+
pBuffer = ippsMalloc_8u( bufSize );
413+
414+
status = ippFunc(src.data, (int)src.step, srcRoiSize, tpl.data, (int)tpl.step, tplRoiSize, (Ipp32f*)dst.data, (int)dst.step, funCfg, pBuffer);
415+
416+
ippsFree( pBuffer );
417+
return status >= 0;
418+
}
419+
420+
#endif
421+
344422
void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
345423
Size corrsize, int ctype,
346424
Point anchor, double delta, int borderType )
347425
{
426+
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
427+
if (ipp_crossCorr(img, _templ, corr))
428+
return;
429+
#endif
430+
348431
const double blockScale = 4.5;
349432
const int minBlockSize = 256;
350433
std::vector<uchar> buf;
@@ -560,6 +643,11 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result,
560643
return;
561644
#endif
562645

646+
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
647+
if (method == CV_TM_SQDIFF && ipp_sqrDistance(img, templ, result))
648+
return;
649+
#endif
650+
563651
int cn = img.channels();
564652
crossCorr( img, templ, result, result.size(), result.type(), Point(0,0), 0, 0);
565653

0 commit comments

Comments
 (0)