Enables support of IPP 9.0.0;

HAVE_IPP_ICV_ONLY will be undefined if OpenCV was linked against ICV packet from IPP9 or greater. ICV9+ packets will be aligned with IPP in OpenCV APIs
This will ease code management between IPP and ICV
This commit is contained in:
Pavel Vlasov 2015-09-25 17:56:19 +03:00
parent 14b006e808
commit 62854dcc0d
9 changed files with 352 additions and 69 deletions

View File

@ -245,6 +245,11 @@ static inline IppDataType ippiGetDataType(int depth)
#define IPP_VERSION_X100 0
#endif
// There shoud be no API difference in OpenCV between ICV and IPP since 9.0
#if (defined HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 900
#undef HAVE_IPP_ICV_ONLY
#endif
#ifdef HAVE_IPP_ICV_ONLY
#define HAVE_ICV 1
#else

View File

@ -3318,28 +3318,102 @@ static void IDCT_64f(const double* src, int src_step, double* dft_src, double* d
}
#ifdef HAVE_IPP
namespace cv
{
#if defined HAVE_IPP && IPP_VERSION_MAJOR >= 7
#if IPP_VERSION_X100 >= 900
typedef IppStatus (CV_STDCALL * ippiDCTFunc)(const Ipp32f* pSrc, int srcStep, Ipp32f* pDst, int dstStep, const void* pDCTSpec, Ipp8u* pBuffer);
typedef IppStatus (CV_STDCALL * ippiDCTInit)(void* pDCTSpec, IppiSize roiSize, Ipp8u* pMemInit );
typedef IppStatus (CV_STDCALL * ippiDCTGetSize)(IppiSize roiSize, int* pSizeSpec, int* pSizeInit, int* pSizeBuf);
#elif IPP_VERSION_X100 >= 700
typedef IppStatus (CV_STDCALL * ippiDCTFunc)(const Ipp32f*, int, Ipp32f*, int, const void*, Ipp8u*);
typedef IppStatus (CV_STDCALL * ippiDCTInitAlloc)(void**, IppiSize, IppHintAlgorithm);
typedef IppStatus (CV_STDCALL * ippiDCTFree)(void* pDCTSpec);
typedef IppStatus (CV_STDCALL * ippiDCTGetBufSize)(const void*, int*);
#endif
template <typename Dct>
class DctIPPLoop_Invoker : public ParallelLoopBody
{
public:
DctIPPLoop_Invoker(const Mat& _src, Mat& _dst, const Dct* _ippidct, bool _inv, bool *_ok) :
ParallelLoopBody(), src(&_src), dst(&_dst), ippidct(_ippidct), inv(_inv), ok(_ok)
DctIPPLoop_Invoker(const Mat& _src, Mat& _dst, bool _inv, bool *_ok) :
ParallelLoopBody(), src(&_src), dst(&_dst), inv(_inv), ok(_ok)
{
*ok = true;
}
virtual void operator()(const Range& range) const
{
if(*ok == false)
return;
#if IPP_VERSION_X100 >= 900
IppiSize srcRoiSize = {src->cols, 1};
int specSize = 0;
int initSize = 0;
int bufferSize = 0;
Ipp8u* pDCTSpec = NULL;
Ipp8u* pBuffer = NULL;
Ipp8u* pInitBuf = NULL;
#define IPP_RETURN \
if(pDCTSpec) \
ippFree(pDCTSpec); \
if(pBuffer) \
ippFree(pBuffer); \
if(pInitBuf) \
ippFree(pInitBuf); \
return;
ippiDCTFunc ippDctFun = inv ? (ippiDCTFunc)ippiDCTInv_32f_C1R : (ippiDCTFunc)ippiDCTFwd_32f_C1R;
ippiDCTInit ippDctInit = inv ? (ippiDCTInit)ippiDCTInvInit_32f : (ippiDCTInit)ippiDCTFwdInit_32f;
ippiDCTGetSize ippDctGetSize = inv ? (ippiDCTGetSize)ippiDCTInvGetSize_32f : (ippiDCTGetSize)ippiDCTFwdGetSize_32f;
if(ippDctGetSize(srcRoiSize, &specSize, &initSize, &bufferSize) < 0)
{
*ok = false;
return;
}
pDCTSpec = (Ipp8u*)ippMalloc(specSize);
if(!pDCTSpec && specSize)
{
*ok = false;
return;
}
pBuffer = (Ipp8u*)ippMalloc(bufferSize);
if(!pBuffer && bufferSize)
{
*ok = false;
IPP_RETURN
}
pInitBuf = (Ipp8u*)ippMalloc(initSize);
if(!pInitBuf && initSize)
{
*ok = false;
IPP_RETURN
}
if(ippDctInit(pDCTSpec, srcRoiSize, pInitBuf) < 0)
{
*ok = false;
IPP_RETURN
}
for(int i = range.start; i < range.end; ++i)
{
if(ippDctFun(src->ptr<float>(i), (int)src->step,dst->ptr<float>(i), (int)dst->step, pDCTSpec, pBuffer) < 0)
{
*ok = false;
IPP_RETURN
}
}
IPP_RETURN
#undef IPP_RETURN
#elif IPP_VERSION_X100 >= 700
void* pDCTSpec;
AutoBuffer<uchar> buf;
uchar* pBuffer = 0;
@ -3349,6 +3423,7 @@ public:
CV_SUPPRESS_DEPRECATED_START
ippiDCTFunc ippDctFun = inv ? (ippiDCTFunc)ippiDCTInv_32f_C1R : (ippiDCTFunc)ippiDCTFwd_32f_C1R;
ippiDCTInitAlloc ippInitAlloc = inv ? (ippiDCTInitAlloc)ippiDCTInvInitAlloc_32f : (ippiDCTInitAlloc)ippiDCTFwdInitAlloc_32f;
ippiDCTFree ippFree = inv ? (ippiDCTFree)ippiDCTInvFree_32f : (ippiDCTFree)ippiDCTFwdFree_32f;
ippiDCTGetBufSize ippGetBufSize = inv ? (ippiDCTGetBufSize)ippiDCTInvGetBufSize_32f : (ippiDCTGetBufSize)ippiDCTFwdGetBufSize_32f;
@ -3359,8 +3434,13 @@ public:
pBuffer = (uchar*)buf;
for( int i = range.start; i < range.end; ++i)
if(!(*ippidct)(src->ptr<float>(i), (int)src->step,dst->ptr<float>(i), (int)dst->step, pDCTSpec, (Ipp8u*)pBuffer))
{
if(ippDctFun(src->ptr<float>(i), (int)src->step,dst->ptr<float>(i), (int)dst->step, pDCTSpec, (Ipp8u*)pBuffer) < 0)
{
*ok = false;
break;
}
}
}
else
*ok = false;
@ -3369,44 +3449,91 @@ public:
ippFree(pDCTSpec);
CV_SUPPRESS_DEPRECATED_END
#else
CV_UNUSED(range);
*ok = false;
#endif
}
private:
const Mat* src;
Mat* dst;
const Dct* ippidct;
bool inv;
bool *ok;
};
template <typename Dct>
bool DctIPPLoop(const Mat& src, Mat& dst, const Dct& ippidct, bool inv)
static bool DctIPPLoop(const Mat& src, Mat& dst, bool inv)
{
bool ok;
parallel_for_(Range(0, src.rows), DctIPPLoop_Invoker<Dct>(src, dst, &ippidct, inv, &ok), src.rows/(double)(1<<4) );
parallel_for_(Range(0, src.rows), DctIPPLoop_Invoker(src, dst, inv, &ok), src.rows/(double)(1<<4) );
return ok;
}
struct IPPDCTFunctor
{
IPPDCTFunctor(ippiDCTFunc _func) : func(_func){}
bool operator()(const Ipp32f* src, int srcStep, Ipp32f* dst, int dstStep, const void* pDCTSpec, Ipp8u* pBuffer) const
{
return func ? func(src, srcStep, dst, dstStep, pDCTSpec, pBuffer) >= 0 : false;
}
private:
ippiDCTFunc func;
};
static bool ippi_DCT_32f(const Mat& src, Mat& dst, bool inv, bool row)
{
ippiDCTFunc ippFunc = inv ? (ippiDCTFunc)ippiDCTInv_32f_C1R : (ippiDCTFunc)ippiDCTFwd_32f_C1R ;
if (row)
return(DctIPPLoop(src,dst,IPPDCTFunctor(ippFunc),inv));
if(row)
return DctIPPLoop(src, dst, inv);
else
{
#if IPP_VERSION_X100 >= 900
IppiSize srcRoiSize = {src.cols, src.rows};
int specSize = 0;
int initSize = 0;
int bufferSize = 0;
Ipp8u* pDCTSpec = NULL;
Ipp8u* pBuffer = NULL;
Ipp8u* pInitBuf = NULL;
#define IPP_RELEASE \
if(pDCTSpec) \
ippFree(pDCTSpec); \
if(pBuffer) \
ippFree(pBuffer); \
if(pInitBuf) \
ippFree(pInitBuf); \
ippiDCTFunc ippDctFun = inv ? (ippiDCTFunc)ippiDCTInv_32f_C1R : (ippiDCTFunc)ippiDCTFwd_32f_C1R;
ippiDCTInit ippDctInit = inv ? (ippiDCTInit)ippiDCTInvInit_32f : (ippiDCTInit)ippiDCTFwdInit_32f;
ippiDCTGetSize ippDctGetSize = inv ? (ippiDCTGetSize)ippiDCTInvGetSize_32f : (ippiDCTGetSize)ippiDCTFwdGetSize_32f;
if(ippDctGetSize(srcRoiSize, &specSize, &initSize, &bufferSize) < 0)
return false;
pDCTSpec = (Ipp8u*)ippMalloc(specSize);
if(!pDCTSpec && specSize)
return false;
pBuffer = (Ipp8u*)ippMalloc(bufferSize);
if(!pBuffer && bufferSize)
{
IPP_RELEASE
return false;
}
pInitBuf = (Ipp8u*)ippMalloc(initSize);
if(!pInitBuf && initSize)
{
IPP_RELEASE
return false;
}
if(ippDctInit(pDCTSpec, srcRoiSize, pInitBuf) < 0)
{
IPP_RELEASE
return false;
}
if(ippDctFun(src.ptr<float>(), (int)src.step,dst.ptr<float>(), (int)dst.step, pDCTSpec, pBuffer) < 0)
{
IPP_RELEASE
return false;
}
IPP_RELEASE
return true;
#undef IPP_RELEASE
#elif IPP_VERSION_X100 >= 700
IppStatus status;
void* pDCTSpec;
AutoBuffer<uchar> buf;
@ -3417,6 +3544,7 @@ static bool ippi_DCT_32f(const Mat& src, Mat& dst, bool inv, bool row)
CV_SUPPRESS_DEPRECATED_START
ippiDCTFunc ippDctFun = inv ? (ippiDCTFunc)ippiDCTInv_32f_C1R : (ippiDCTFunc)ippiDCTFwd_32f_C1R;
ippiDCTInitAlloc ippInitAlloc = inv ? (ippiDCTInitAlloc)ippiDCTInvInitAlloc_32f : (ippiDCTInitAlloc)ippiDCTFwdInitAlloc_32f;
ippiDCTFree ippFree = inv ? (ippiDCTFree)ippiDCTInvFree_32f : (ippiDCTFree)ippiDCTFwdFree_32f;
ippiDCTGetBufSize ippGetBufSize = inv ? (ippiDCTGetBufSize)ippiDCTInvGetBufSize_32f : (ippiDCTGetBufSize)ippiDCTFwdGetBufSize_32f;
@ -3428,7 +3556,7 @@ static bool ippi_DCT_32f(const Mat& src, Mat& dst, bool inv, bool row)
buf.allocate( bufSize );
pBuffer = (uchar*)buf;
status = ippFunc(src.ptr<float>(), (int)src.step, dst.ptr<float>(), (int)dst.step, pDCTSpec, (Ipp8u*)pBuffer);
status = ippDctFun(src.ptr<float>(), (int)src.step, dst.ptr<float>(), (int)dst.step, pDCTSpec, (Ipp8u*)pBuffer);
}
if (pDCTSpec)
@ -3437,11 +3565,14 @@ static bool ippi_DCT_32f(const Mat& src, Mat& dst, bool inv, bool row)
CV_SUPPRESS_DEPRECATED_END
return status >= 0;
#else
CV_UNUSED(src); CV_UNUSED(dst); CV_UNUSED(inv); CV_UNUSED(row);
return false;
#endif
}
}
#endif
}
#endif
void cv::dct( InputArray _src0, OutputArray _dst, int flags )
{

View File

@ -2233,7 +2233,9 @@ static bool ipp_minMaxIdx( Mat &src, double* minVal, double* maxVal, int* minIdx
CV_SUPPRESS_DEPRECATED_START
ippiMaskMinMaxIndxFuncC1 ippFuncC1 =
type == CV_8UC1 ? (ippiMaskMinMaxIndxFuncC1)ippiMinMaxIndx_8u_C1MR :
#if IPP_VERSION_X100 < 900
type == CV_8SC1 ? (ippiMaskMinMaxIndxFuncC1)ippiMinMaxIndx_8s_C1MR :
#endif
type == CV_16UC1 ? (ippiMaskMinMaxIndxFuncC1)ippiMinMaxIndx_16u_C1MR :
type == CV_32FC1 ? (ippiMaskMinMaxIndxFuncC1)ippiMinMaxIndx_32f_C1MR : 0;
CV_SUPPRESS_DEPRECATED_END
@ -2270,8 +2272,12 @@ static bool ipp_minMaxIdx( Mat &src, double* minVal, double* maxVal, int* minIdx
CV_SUPPRESS_DEPRECATED_START
ippiMinMaxIndxFuncC1 ippFuncC1 =
#if IPP_VERSION_X100 != 900 // bug in 9.0.0 avx2 optimization
depth == CV_8U ? (ippiMinMaxIndxFuncC1)ippiMinMaxIndx_8u_C1R :
#endif
#if IPP_VERSION_X100 < 900
depth == CV_8S ? (ippiMinMaxIndxFuncC1)ippiMinMaxIndx_8s_C1R :
#endif
depth == CV_16U ? (ippiMinMaxIndxFuncC1)ippiMinMaxIndx_16u_C1R :
#if !((defined _MSC_VER && defined _M_IX86) || defined __i386__)
depth == CV_32F ? (ippiMinMaxIndxFuncC1)ippiMinMaxIndx_32f_C1R :
@ -2676,19 +2682,25 @@ static bool ipp_norm(Mat &src, int normType, Mat &mask, double &result)
ippiMaskNormFuncC1 ippFuncC1 =
normType == NORM_INF ?
(type == CV_8UC1 ? (ippiMaskNormFuncC1)ippiNorm_Inf_8u_C1MR :
#if IPP_VERSION_X100 < 900
type == CV_8SC1 ? (ippiMaskNormFuncC1)ippiNorm_Inf_8s_C1MR :
#endif
// type == CV_16UC1 ? (ippiMaskNormFuncC1)ippiNorm_Inf_16u_C1MR :
type == CV_32FC1 ? (ippiMaskNormFuncC1)ippiNorm_Inf_32f_C1MR :
0) :
normType == NORM_L1 ?
(type == CV_8UC1 ? (ippiMaskNormFuncC1)ippiNorm_L1_8u_C1MR :
#if IPP_VERSION_X100 < 900
type == CV_8SC1 ? (ippiMaskNormFuncC1)ippiNorm_L1_8s_C1MR :
#endif
type == CV_16UC1 ? (ippiMaskNormFuncC1)ippiNorm_L1_16u_C1MR :
type == CV_32FC1 ? (ippiMaskNormFuncC1)ippiNorm_L1_32f_C1MR :
0) :
normType == NORM_L2 || normType == NORM_L2SQR ?
(type == CV_8UC1 ? (ippiMaskNormFuncC1)ippiNorm_L2_8u_C1MR :
#if IPP_VERSION_X100 < 900
type == CV_8SC1 ? (ippiMaskNormFuncC1)ippiNorm_L2_8s_C1MR :
#endif
type == CV_16UC1 ? (ippiMaskNormFuncC1)ippiNorm_L2_16u_C1MR :
type == CV_32FC1 ? (ippiMaskNormFuncC1)ippiNorm_L2_32f_C1MR :
0) : 0;
@ -2701,7 +2713,7 @@ static bool ipp_norm(Mat &src, int normType, Mat &mask, double &result)
return true;
}
}
#if IPP_DISABLED_BLOCK
#if IPP_DISABLE_BLOCK
typedef IppStatus (CV_STDCALL* ippiMaskNormFuncC3)(const void *, int, const void *, int, IppiSize, int, Ipp64f *);
ippiMaskNormFuncC3 ippFuncC3 =
normType == NORM_INF ?
@ -3071,23 +3083,29 @@ static bool ipp_norm(InputArray _src1, InputArray _src2, int normType, InputArra
ippiMaskNormRelFuncC1 ippFuncC1 =
normType == NORM_INF ?
(type == CV_8UC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_Inf_8u_C1MR :
#if IPP_VERSION_X100 < 900
#ifndef __APPLE__
type == CV_8SC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_Inf_8s_C1MR :
#endif
#endif
type == CV_16UC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_Inf_16u_C1MR :
type == CV_32FC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_Inf_32f_C1MR :
0) :
normType == NORM_L1 ?
(type == CV_8UC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_L1_8u_C1MR :
#if IPP_VERSION_X100 < 900
#ifndef __APPLE__
type == CV_8SC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_L1_8s_C1MR :
#endif
#endif
type == CV_16UC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_L1_16u_C1MR :
type == CV_32FC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_L1_32f_C1MR :
0) :
normType == NORM_L2 || normType == NORM_L2SQR ?
(type == CV_8UC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_L2_8u_C1MR :
#if IPP_VERSION_X100 < 900
type == CV_8SC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_L2_8s_C1MR :
#endif
type == CV_16UC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_L2_16u_C1MR :
type == CV_32FC1 ? (ippiMaskNormRelFuncC1)ippiNormRel_L2_32f_C1MR :
0) : 0;
@ -3172,21 +3190,27 @@ static bool ipp_norm(InputArray _src1, InputArray _src2, int normType, InputArra
ippiMaskNormDiffFuncC1 ippFuncC1 =
normType == NORM_INF ?
(type == CV_8UC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_Inf_8u_C1MR :
#if IPP_VERSION_X100 < 900
type == CV_8SC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_Inf_8s_C1MR :
#endif
type == CV_16UC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_Inf_16u_C1MR :
type == CV_32FC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_Inf_32f_C1MR :
0) :
normType == NORM_L1 ?
(type == CV_8UC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L1_8u_C1MR :
#if IPP_VERSION_X100 < 900
#ifndef __APPLE__
type == CV_8SC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L1_8s_C1MR :
#endif
#endif
type == CV_16UC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L1_16u_C1MR :
type == CV_32FC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L1_32f_C1MR :
0) :
normType == NORM_L2 || normType == NORM_L2SQR ?
(type == CV_8UC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L2_8u_C1MR :
#if IPP_VERSION_X100 < 900
type == CV_8SC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L2_8s_C1MR :
#endif
type == CV_16UC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L2_16u_C1MR :
type == CV_32FC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L2_32f_C1MR :
0) : 0;
@ -3204,19 +3228,25 @@ static bool ipp_norm(InputArray _src1, InputArray _src2, int normType, InputArra
ippiMaskNormDiffFuncC3 ippFuncC3 =
normType == NORM_INF ?
(type == CV_8UC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_Inf_8u_C3CMR :
#if IPP_VERSION_X100 < 900
type == CV_8SC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_Inf_8s_C3CMR :
#endif
type == CV_16UC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_Inf_16u_C3CMR :
type == CV_32FC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_Inf_32f_C3CMR :
0) :
normType == NORM_L1 ?
(type == CV_8UC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_L1_8u_C3CMR :
#if IPP_VERSION_X100 < 900
type == CV_8SC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_L1_8s_C3CMR :
#endif
type == CV_16UC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_L1_16u_C3CMR :
type == CV_32FC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_L1_32f_C3CMR :
0) :
normType == NORM_L2 || normType == NORM_L2SQR ?
(type == CV_8UC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_L2_8u_C3CMR :
#if IPP_VERSION_X100 < 900
type == CV_8SC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_L2_8s_C3CMR :
#endif
type == CV_16UC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_L2_16u_C3CMR :
type == CV_32FC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_L2_32f_C3CMR :
0) : 0;

View File

@ -60,10 +60,16 @@ static bool ippCanny(const Mat& _src, Mat& _dst, float low, float high)
int size = 0, size1 = 0;
IppiSize roi = { _src.cols, _src.rows };
#if IPP_VERSION_X100 < 900
if (ippiFilterSobelNegVertGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size) < 0)
return false;
if (ippiFilterSobelHorizGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size1) < 0)
return false;
#else
if(ippiFilterSobelGetBufferSize(roi, ippMskSize3x3, ippNormL2, ipp8u, ipp16s, 1, &size) < 0)
return false;
#endif
size = std::max(size, size1);
if (ippiCannyGetSize(roi, &size1) < 0)

View File

@ -7416,6 +7416,7 @@ static bool ipp_cvtColor( Mat &src, OutputArray _dst, int code, int dcn )
return false;
#endif
#if IPP_VERSION_X100 < 900
case CV_BGR5652BGR: case CV_BGR5552BGR: case CV_BGR5652RGB: case CV_BGR5552RGB:
case CV_BGR5652BGRA: case CV_BGR5552BGRA: case CV_BGR5652RGBA: case CV_BGR5552RGBA:
if(dcn <= 0) dcn = (code==CV_BGR5652BGRA || code==CV_BGR5552BGRA || code==CV_BGR5652RGBA || code==CV_BGR5552RGBA) ? 4 : 3;
@ -7449,6 +7450,7 @@ static bool ipp_cvtColor( Mat &src, OutputArray _dst, int code, int dcn )
}
CV_SUPPRESS_DEPRECATED_END
return false;
#endif
#if IPP_VERSION_X100 >= 700
case CV_BGR2GRAY: case CV_BGRA2GRAY: case CV_RGB2GRAY: case CV_RGBA2GRAY:

View File

@ -325,11 +325,19 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx,
if (src.type() == CV_8U && dst.type() == CV_16S && scale == 1)
{
#if IPP_VERSION_X100 >= 900
if(ippiFilterSobelGetBufferSize(roi, kernel, ippNormL2, ipp8u, ipp16s, 1, &bufSize) < 0)
return false;
buffer.allocate(bufSize);
#endif
if ((dx == 1) && (dy == 0))
{
#if IPP_VERSION_X100 < 900
if (0 > ippiFilterSobelNegVertGetBufferSize_8u16s_C1R(roi, kernel,&bufSize))
return false;
buffer.allocate(bufSize);
#endif
if (0 > ippiFilterSobelNegVertBorder_8u16s_C1R(src.ptr<Ipp8u>(), (int)src.step,
dst.ptr<Ipp16s>(), (int)dst.step, roi, kernel,
@ -340,9 +348,11 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx,
if ((dx == 0) && (dy == 1))
{
#if IPP_VERSION_X100 < 900
if (0 > ippiFilterSobelHorizGetBufferSize_8u16s_C1R(roi, kernel,&bufSize))
return false;
buffer.allocate(bufSize);
#endif
if (0 > ippiFilterSobelHorizBorder_8u16s_C1R(src.ptr<Ipp8u>(), (int)src.step,
dst.ptr<Ipp16s>(), (int)dst.step, roi, kernel,
@ -354,9 +364,11 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx,
#if !defined(HAVE_IPP_ICV_ONLY)
if ((dx == 2) && (dy == 0))
{
#if IPP_VERSION_X100 < 900
if (0 > ippiFilterSobelVertSecondGetBufferSize_8u16s_C1R(roi, kernel,&bufSize))
return false;
buffer.allocate(bufSize);
#endif
if (0 > ippiFilterSobelVertSecondBorder_8u16s_C1R(src.ptr<Ipp8u>(), (int)src.step,
dst.ptr<Ipp16s>(), (int)dst.step, roi, kernel,
@ -367,9 +379,11 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx,
if ((dx == 0) && (dy == 2))
{
#if IPP_VERSION_X100 < 900
if (0 > ippiFilterSobelHorizSecondGetBufferSize_8u16s_C1R(roi, kernel,&bufSize))
return false;
buffer.allocate(bufSize);
#endif
if (0 > ippiFilterSobelHorizSecondBorder_8u16s_C1R(src.ptr<Ipp8u>(), (int)src.step,
dst.ptr<Ipp16s>(), (int)dst.step, roi, kernel,
@ -382,12 +396,20 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx,
if (src.type() == CV_32F && dst.type() == CV_32F)
{
#if IPP_VERSION_X100 >= 900
if(ippiFilterSobelGetBufferSize(roi, kernel, ippNormL2, ipp32f, ipp32f, 1, &bufSize) < 0)
return false;
buffer.allocate(bufSize);
#endif
#if IPP_DISABLE_BLOCK
if ((dx == 1) && (dy == 0))
{
#if IPP_VERSION_X100 < 900
if (0 > ippiFilterSobelNegVertGetBufferSize_32f_C1R(roi, kernel, &bufSize))
return false;
buffer.allocate(bufSize);
#endif
if (0 > ippiFilterSobelNegVertBorder_32f_C1R(src.ptr<Ipp32f>(), (int)src.step,
dst.ptr<Ipp32f>(), (int)dst.step, roi, kernel,
@ -400,9 +422,12 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx,
if ((dx == 0) && (dy == 1))
{
#if IPP_VERSION_X100 < 900
if (0 > ippiFilterSobelHorizGetBufferSize_32f_C1R(roi, kernel,&bufSize))
return false;
buffer.allocate(bufSize);
#endif
if (0 > ippiFilterSobelHorizBorder_32f_C1R(src.ptr<Ipp32f>(), (int)src.step,
dst.ptr<Ipp32f>(), (int)dst.step, roi, kernel,
ippBorderRepl, 0, (Ipp8u*)(char*)buffer))
@ -415,9 +440,11 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx,
#if !defined(HAVE_IPP_ICV_ONLY)
if((dx == 2) && (dy == 0))
{
#if IPP_VERSION_X100 < 900
if (0 > ippiFilterSobelVertSecondGetBufferSize_32f_C1R(roi, kernel,&bufSize))
return false;
buffer.allocate(bufSize);
#endif
if (0 > ippiFilterSobelVertSecondBorder_32f_C1R(src.ptr<Ipp32f>(), (int)src.step,
dst.ptr<Ipp32f>(), (int)dst.step, roi, kernel,
@ -430,9 +457,11 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx,
if((dx == 0) && (dy == 2))
{
#if IPP_VERSION_X100 < 900
if (0 > ippiFilterSobelHorizSecondGetBufferSize_32f_C1R(roi, kernel,&bufSize))
return false;
buffer.allocate(bufSize);
#endif
if (0 > ippiFilterSobelHorizSecondBorder_32f_C1R(src.ptr<Ipp32f>(), (int)src.step,
dst.ptr<Ipp32f>(), (int)dst.step, roi, kernel,

View File

@ -1180,7 +1180,7 @@ class IPPCalcHistInvoker :
public ParallelLoopBody
{
public:
IPPCalcHistInvoker(const Mat & _src, Mat & _hist, AutoBuffer<Ipp32s> & _levels, Ipp32s _histSize, Ipp32s _low, Ipp32s _high, bool * _ok) :
IPPCalcHistInvoker(const Mat & _src, Mat & _hist, AutoBuffer<Ipp32f> & _levels, Ipp32s _histSize, Ipp32f _low, Ipp32f _high, bool * _ok) :
ParallelLoopBody(), src(&_src), hist(&_hist), levels(&_levels), histSize(_histSize), low(_low), high(_high), ok(_ok)
{
*ok = true;
@ -1189,12 +1189,54 @@ public:
virtual void operator() (const Range & range) const
{
Mat phist(hist->size(), hist->type(), Scalar::all(0));
#if IPP_VERSION_X100 >= 900
IppiSize roi = {src->cols, range.end - range.start};
int bufferSize = 0;
int specSize = 0;
IppiHistogramSpec *pSpec = NULL;
Ipp8u *pBuffer = NULL;
IppStatus status = ippiHistogramEven_8u_C1R(
src->ptr(range.start), (int)src->step, ippiSize(src->cols, range.end - range.start),
phist.ptr<Ipp32s>(), (Ipp32s *)*levels, histSize, low, high);
if(ippiHistogramGetBufferSize(ipp8u, roi, &histSize, 1, 1, &specSize, &bufferSize) < 0)
{
*ok = false;
return;
}
if (status < 0)
pBuffer = (Ipp8u*)ippMalloc(bufferSize);
if(!pBuffer && bufferSize)
{
*ok = false;
return;
}
pSpec = (IppiHistogramSpec*)ippMalloc(specSize);
if(!pSpec && specSize)
{
if(pBuffer) ippFree(pBuffer);
*ok = false;
return;
}
if(ippiHistogramUniformInit(ipp8u, (Ipp32f*)&low, (Ipp32f*)&high, (Ipp32s*)&histSize, 1, pSpec) < 0)
{
if(pSpec) ippFree(pSpec);
if(pBuffer) ippFree(pBuffer);
*ok = false;
return;
}
IppStatus status = ippiHistogram_8u_C1R(src->ptr(range.start), (int)src->step, ippiSize(src->cols, range.end - range.start),
phist.ptr<Ipp32u>(), pSpec, pBuffer);
if(pSpec) ippFree(pSpec);
if(pBuffer) ippFree(pBuffer);
#else
CV_SUPPRESS_DEPRECATED_START
IppStatus status = ippiHistogramEven_8u_C1R(src->ptr(range.start), (int)src->step, ippiSize(src->cols, range.end - range.start),
phist.ptr<Ipp32s>(), (Ipp32s*)(Ipp32f*)*levels, histSize, (Ipp32s)low, (Ipp32s)high);
CV_SUPPRESS_DEPRECATED_END
#endif
if(status < 0)
{
*ok = false;
return;
@ -1207,8 +1249,9 @@ public:
private:
const Mat * src;
Mat * hist;
AutoBuffer<Ipp32s> * levels;
Ipp32s histSize, low, high;
AutoBuffer<Ipp32f> * levels;
Ipp32s histSize;
Ipp32f low, high;
bool * ok;
const IPPCalcHistInvoker & operator = (const IPPCalcHistInvoker & );
@ -1239,7 +1282,7 @@ static bool ipp_calchist(const Mat* images, int nimages, const int* channels,
!accumulate && uniform)
{
ihist.setTo(Scalar::all(0));
AutoBuffer<Ipp32s> levels(histSize[0] + 1);
AutoBuffer<Ipp32f> levels(histSize[0] + 1);
bool ok = true;
const Mat & src = images[0];
@ -1247,7 +1290,7 @@ static bool ipp_calchist(const Mat* images, int nimages, const int* channels,
#ifdef HAVE_CONCURRENCY
nstripes = 1;
#endif
IPPCalcHistInvoker invoker(src, ihist, levels, histSize[0] + 1, (Ipp32s)ranges[0][0], (Ipp32s)ranges[0][1], &ok);
IPPCalcHistInvoker invoker(src, ihist, levels, histSize[0] + 1, ranges[0][0], ranges[0][1], &ok);
Range range(0, src.rows);
parallel_for_(range, invoker, nstripes);

View File

@ -1155,7 +1155,36 @@ static bool ipp_MorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kern
if (!rectKernel)
{
#if 1
#if IPP_VERSION_X100 >= 900
if (((kernel.cols - 1) / 2 != anchor.x) || ((kernel.rows - 1) / 2 != anchor.y))
return false;
#define IPP_MORPH_CASE(cvtype, flavor, data_type) \
case cvtype: \
{\
int specSize = 0, bufferSize = 0;\
if (0 > ippiMorphologyBorderGetSize_##flavor(roiSize, kernelSize, &specSize, &bufferSize))\
return false;\
IppiMorphState *pSpec = (IppiMorphState*)ippMalloc(specSize);\
Ipp8u *pBuffer = (Ipp8u*)ippMalloc(bufferSize);\
if (0 > ippiMorphologyBorderInit_##flavor(roiSize, kernel.ptr(), kernelSize, pSpec, pBuffer))\
{\
ippFree(pBuffer);\
ippFree(pSpec);\
return false;\
}\
bool ok = false;\
if (op == MORPH_ERODE)\
ok = (0 <= ippiErodeBorder_##flavor(_src->ptr<Ipp##data_type>(), (int)_src->step[0], dst.ptr<Ipp##data_type>(), (int)dst.step[0],\
roiSize, ippBorderRepl, 0, pSpec, pBuffer));\
else\
ok = (0 <= ippiDilateBorder_##flavor(_src->ptr<Ipp##data_type>(), (int)_src->step[0], dst.ptr<Ipp##data_type>(), (int)dst.step[0],\
roiSize, ippBorderRepl, 0, pSpec, pBuffer));\
ippFree(pBuffer);\
ippFree(pSpec);\
return ok;\
}\
break;
#else
if (((kernel.cols - 1) / 2 != anchor.x) || ((kernel.rows - 1) / 2 != anchor.y))
return false;
#define IPP_MORPH_CASE(cvtype, flavor, data_type) \
@ -1184,35 +1213,8 @@ static bool ipp_MorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kern
return ok;\
}\
break;
#else
IppiPoint point = {anchor.x, anchor.y};
// this is case, which can be used with the anchor not in center of the kernel, but
// ippiMorphologyBorderGetSize_, ippiErodeBorderReplicate_ and ippiDilateBorderReplicate_ are deprecated.
#define IPP_MORPH_CASE(cvtype, flavor, data_type) \
case cvtype: \
{\
int specSize = 0;\
int bufferSize = 0;\
if (0 > ippiMorphologyGetSize_##flavor( roiSize.width, kernel.ptr() kernelSize, &specSize))\
return false;\
bool ok = false;\
IppiMorphState* pState = (IppiMorphState*)ippMalloc(specSize);\
if (ippiMorphologyInit_##flavor(roiSize.width, kernel.ptr(), kernelSize, point, pState) >= 0)\
{\
if (op == MORPH_ERODE)\
ok = ippiErodeBorderReplicate_##flavor(_src->ptr<Ipp##data_type>(), (int)_src->step[0],\
dst.ptr<Ipp##data_type>(), (int)dst.step[0],\
roiSize, ippBorderRepl, pState ) >= 0;\
else\
ok = ippiDilateBorderReplicate_##flavor(_src->ptr<Ipp##data_type>(), (int)_src->step[0],\
dst.ptr<Ipp##data_type>(), (int)dst.step[0],\
roiSize, ippBorderRepl, pState ) >= 0;\
}\
ippFree(pState);\
return ok;\
}\
break;
#endif
CV_SUPPRESS_DEPRECATED_START
switch (type)
{
IPP_MORPH_CASE(CV_8UC1, 8u_C1R, 8u);
@ -1224,11 +1226,39 @@ static bool ipp_MorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kern
default:
;
}
CV_SUPPRESS_DEPRECATED_END
#undef IPP_MORPH_CASE
}
else
{
#if IPP_VERSION_X100 >= 900
if (((kernel.cols - 1) / 2 != anchor.x) || ((kernel.rows - 1) / 2 != anchor.y)) // Arbitrary anchor is no longer supporeted since IPP 9.0.0
return false;
#define IPP_MORPH_CASE(cvtype, flavor, data_type) \
case cvtype: \
{\
if (op == MORPH_ERODE)\
{\
int bufSize = 0;\
if (0 > ippiFilterMinBorderGetBufferSize(roiSize, kernelSize, ipp##data_type, 1, &bufSize))\
return false;\
AutoBuffer<uchar> buf(bufSize + 64);\
uchar* buffer = alignPtr((uchar*)buf, 32);\
return (0 <= ippiFilterMinBorder_##flavor(_src->ptr<Ipp##data_type>(), (int)_src->step[0], dst.ptr<Ipp##data_type>(), (int)dst.step[0], roiSize, kernelSize, ippBorderRepl, 0, buffer));\
}\
else\
{\
int bufSize = 0;\
if (0 > ippiFilterMaxBorderGetBufferSize(roiSize, kernelSize, ipp##data_type, 1, &bufSize))\
return false;\
AutoBuffer<uchar> buf(bufSize + 64);\
uchar* buffer = alignPtr((uchar*)buf, 32);\
return (0 <= ippiFilterMaxBorder_##flavor(_src->ptr<Ipp##data_type>(), (int)_src->step[0], dst.ptr<Ipp##data_type>(), (int)dst.step[0], roiSize, kernelSize, ippBorderRepl, 0, buffer));\
}\
}\
break;
#else
IppiPoint point = {anchor.x, anchor.y};
#define IPP_MORPH_CASE(cvtype, flavor, data_type) \
@ -1244,7 +1274,9 @@ static bool ipp_MorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kern
return (0 <= ippiFilterMaxBorderReplicate_##flavor(_src->ptr<Ipp##data_type>(), (int)_src->step[0], dst.ptr<Ipp##data_type>(), (int)dst.step[0], roiSize, kernelSize, point, buffer));\
}\
break;
#endif
CV_SUPPRESS_DEPRECATED_START
switch (type)
{
IPP_MORPH_CASE(CV_8UC1, 8u_C1R, 8u);
@ -1256,6 +1288,7 @@ static bool ipp_MorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kern
default:
;
}
CV_SUPPRESS_DEPRECATED_END
#undef IPP_MORPH_CASE
}
#else

View File

@ -165,7 +165,11 @@ icvReleaseHidHaarClassifierCascade( CvHidHaarClassifierCascade** _cascade )
for( i = 0; i < cascade->count; i++ )
{
if( cascade->ipp_stages[i] )
#if IPP_VERSION_X100 < 900
ippiHaarClassifierFree_32f( (IppiHaarClassifier_32f*)cascade->ipp_stages[i] );
#else
cvFree(&cascade->ipp_stages[i]);
#endif
}
}
cvFree( &cascade->ipp_stages );