mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
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:
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user