From 40b2dfae096eab7693bafe3207d7c1d8406cb440 Mon Sep 17 00:00:00 2001 From: Pavel Vlasov Date: Tue, 13 Oct 2015 10:41:09 +0300 Subject: [PATCH] Fix for filter2D and IPP < 900 --- modules/imgproc/src/filter.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index 42a1130a3..5eec45f9f 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -4579,7 +4579,11 @@ static bool ipp_filter2D( InputArray _src, OutputArray _dst, int ddepth, int stype = src.type(), sdepth = CV_MAT_DEPTH(stype), cn = CV_MAT_CN(stype), ktype = kernel.type(), kdepth = CV_MAT_DEPTH(ktype); bool isolated = (borderType & BORDER_ISOLATED) != 0; +#if IPP_VERSION_X100 >= 900 Point ippAnchor((kernel.cols-1)/2, (kernel.rows-1)/2); +#else + Point ippAnchor(kernel.cols >> 1, kernel.rows >> 1); +#endif int borderTypeNI = borderType & ~BORDER_ISOLATED; IppiBorderType ippBorderType = ippiGetBorderType(borderTypeNI); @@ -4618,13 +4622,21 @@ static bool ipp_filter2D( InputArray _src, OutputArray _dst, int ddepth, { Ipp32f *pKerBuffer = (Ipp32f*)kernel.data; IppAutoBuffer kerTmp; - if(kernel.step != kernel.cols) + int kerStep = sizeof(Ipp32f)*kernelSize.width; +#if IPP_VERSION_X100 >= 900 + if(kernel.step != kerStep) { - kerTmp.Alloc(sizeof(Ipp32f)*kernelSize.width*kernelSize.height); - if(ippiCopy_32f_C1R((Ipp32f*)kernel.data, (int)kernel.step, kerTmp, kernelSize.width*sizeof(Ipp32f), kernelSize) < 0) + kerTmp.Alloc(kerStep*kernelSize.height); + if(ippiCopy_32f_C1R((Ipp32f*)kernel.data, (int)kernel.step, kerTmp, kerStep, kernelSize) < 0) return false; pKerBuffer = kerTmp; } +#else + kerTmp.Alloc(kerStep*kernelSize.height); + Mat kerFlip(Size(kernelSize.width, kernelSize.height), CV_32FC1, kerTmp, kerStep); + flip(kernel, kerFlip, -1); + pKerBuffer = kerTmp; +#endif if((status = ippiFilterBorderInit_32f(pKerBuffer, kernelSize, dataType, cn, ippRndFinancial, spec)) >= 0 ) @@ -4637,13 +4649,21 @@ static bool ipp_filter2D( InputArray _src, OutputArray _dst, int ddepth, { Ipp16s *pKerBuffer = (Ipp16s*)kernel.data; IppAutoBuffer kerTmp; - if(kernel.step != kernel.cols) + int kerStep = sizeof(Ipp16s)*kernelSize.width; +#if IPP_VERSION_X100 >= 900 + if(kernel.step != kerStep) { - kerTmp.Alloc(sizeof(Ipp16s)*kernelSize.width*kernelSize.height); - if(ippiCopy_16s_C1R((Ipp16s*)kernel.data, (int)kernel.step, kerTmp, kernelSize.width*sizeof(Ipp16s), kernelSize) < 0) + kerTmp.Alloc(kerStep*kernelSize.height); + if(ippiCopy_16s_C1R((Ipp16s*)kernel.data, (int)kernel.step, kerTmp, kerStep, kernelSize) < 0) return false; pKerBuffer = kerTmp; } +#else + kerTmp.Alloc(kerStep*kernelSize.height); + Mat kerFlip(Size(kernelSize.width, kernelSize.height), CV_16SC1, kerTmp, kerStep); + flip(kernel, kerFlip, -1); + pKerBuffer = kerTmp; +#endif if((status = ippiFilterBorderInit_16s(pKerBuffer, kernelSize, 0, dataType, cn, ippRndFinancial, spec)) >= 0)