mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge branch '4.x' into '5.x'
This commit is contained in:
+189
-58
@@ -611,9 +611,14 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
|
||||
#endif
|
||||
|
||||
typedef int (*ExtendedTypeFunc)(const uchar* src1, size_t step1,
|
||||
const uchar* src2, size_t step2,
|
||||
uchar* dst, size_t step, int width, int height,
|
||||
void*);
|
||||
|
||||
static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
InputArray _mask, int dtype, BinaryFuncC* tab, bool muldiv=false,
|
||||
void* usrdata=0, int oclop=-1 )
|
||||
void* usrdata=0, int oclop=-1, ExtendedTypeFunc extendedFunc = nullptr )
|
||||
{
|
||||
const _InputArray *psrc1 = &_src1, *psrc2 = &_src2;
|
||||
_InputArray::KindFlag kind1 = psrc1->kind(), kind2 = psrc2->kind();
|
||||
@@ -643,10 +648,13 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
|
||||
Mat src1 = psrc1->getMat(), src2 = psrc2->getMat(), dst = _dst.getMat();
|
||||
Size sz = getContinuousSize2D(src1, src2, dst, src1.channels());
|
||||
BinaryFuncC func = tab[depth1];
|
||||
CV_Assert(func != 0);
|
||||
func(src1.ptr(), src1.step, src2.ptr(), src2.step,
|
||||
dst.ptr(), dst.step, sz.width, sz.height, usrdata);
|
||||
if (!extendedFunc || extendedFunc(src1.ptr(), src1.step, src2.ptr(), src2.step,
|
||||
dst.ptr(), dst.step, sz.width, sz.height, usrdata) != 0)
|
||||
{
|
||||
BinaryFuncC func = tab[depth1];
|
||||
CV_Assert(func);
|
||||
func(src1.ptr(), src1.step, src2.ptr(), src2.step, dst.ptr(), dst.step, sz.width, sz.height, usrdata);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -776,14 +784,22 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
_buf.allocate(bufesz*blocksize + 64);
|
||||
buf = _buf.data();
|
||||
if( cvtsrc1 )
|
||||
{
|
||||
buf1 = buf, buf = alignPtr(buf + blocksize*wsz, 16);
|
||||
}
|
||||
if( cvtsrc2 )
|
||||
{
|
||||
buf2 = buf, buf = alignPtr(buf + blocksize*wsz, 16);
|
||||
}
|
||||
wbuf = maskbuf = buf;
|
||||
if( cvtdst )
|
||||
{
|
||||
buf = alignPtr(buf + blocksize*wsz, 16);
|
||||
}
|
||||
if( haveMask )
|
||||
{
|
||||
maskbuf = buf;
|
||||
}
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
{
|
||||
@@ -793,38 +809,44 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
Size bszn(bsz*cn, 1);
|
||||
const uchar *sptr1 = ptrs[0], *sptr2 = ptrs[1];
|
||||
uchar* dptr = ptrs[2];
|
||||
if( cvtsrc1 )
|
||||
// try to perform operation with conversion in one call
|
||||
// if fail, use converter functions
|
||||
uchar* opconverted = haveMask ? maskbuf : dptr;
|
||||
if (!extendedFunc || extendedFunc(sptr1, 1, sptr2, 1, opconverted, (!haveMask),
|
||||
bszn.width, bszn.height, usrdata) != 0)
|
||||
{
|
||||
cvtsrc1( sptr1, 1, 0, 1, buf1, 1, bszn, 0 );
|
||||
sptr1 = buf1;
|
||||
}
|
||||
if( ptrs[0] == ptrs[1] )
|
||||
sptr2 = sptr1;
|
||||
else if( cvtsrc2 )
|
||||
{
|
||||
cvtsrc2( sptr2, 1, 0, 1, buf2, 1, bszn, 0 );
|
||||
sptr2 = buf2;
|
||||
if( cvtsrc1 )
|
||||
{
|
||||
cvtsrc1( sptr1, 1, 0, 1, buf1, 1, bszn, 0 );
|
||||
sptr1 = buf1;
|
||||
}
|
||||
if( ptrs[0] == ptrs[1] )
|
||||
{
|
||||
sptr2 = sptr1;
|
||||
}
|
||||
else if( cvtsrc2 )
|
||||
{
|
||||
cvtsrc2( sptr2, 1, 0, 1, buf2, 1, bszn, 0 );
|
||||
sptr2 = buf2;
|
||||
}
|
||||
|
||||
uchar* fdst = (haveMask || cvtdst) ? wbuf : dptr;
|
||||
func(sptr1, 1, sptr2, 1, fdst, (!haveMask && !cvtdst), bszn.width, bszn.height, usrdata);
|
||||
|
||||
if (cvtdst)
|
||||
{
|
||||
uchar* cdst = haveMask ? maskbuf : dptr;
|
||||
cvtdst(wbuf, 1, 0, 1, cdst, 1, bszn, 0);
|
||||
}
|
||||
opconverted = cvtdst ? maskbuf : wbuf;
|
||||
}
|
||||
|
||||
if( !haveMask && !cvtdst )
|
||||
func( sptr1, 1, sptr2, 1, dptr, 1, bszn.width, bszn.height, usrdata );
|
||||
else
|
||||
if (haveMask)
|
||||
{
|
||||
func( sptr1, 1, sptr2, 1, wbuf, 0, bszn.width, bszn.height, usrdata );
|
||||
if( !haveMask )
|
||||
cvtdst( wbuf, 1, 0, 1, dptr, 1, bszn, 0 );
|
||||
else if( !cvtdst )
|
||||
{
|
||||
copymask( wbuf, 1, ptrs[3], 1, dptr, 1, Size(bsz, 1), &dsz );
|
||||
ptrs[3] += bsz;
|
||||
}
|
||||
else
|
||||
{
|
||||
cvtdst( wbuf, 1, 0, 1, maskbuf, 1, bszn, 0 );
|
||||
copymask( maskbuf, 1, ptrs[3], 1, dptr, 1, Size(bsz, 1), &dsz );
|
||||
ptrs[3] += bsz;
|
||||
}
|
||||
copymask(opconverted, 1, ptrs[3], 1, dptr, 1, Size(bsz, 1), &dsz);
|
||||
ptrs[3] += bsz;
|
||||
}
|
||||
|
||||
ptrs[0] += bsz*esz1; ptrs[1] += bsz*esz2; ptrs[2] += bsz*dsz;
|
||||
}
|
||||
}
|
||||
@@ -840,13 +862,19 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
_buf.allocate(bufesz*blocksize + 64);
|
||||
buf = _buf.data();
|
||||
if( cvtsrc1 )
|
||||
buf1 = buf, buf = alignPtr(buf + blocksize*wsz, 16);
|
||||
{
|
||||
buf1 = buf, buf = alignPtr(buf + blocksize * wsz, 16);
|
||||
}
|
||||
buf2 = buf; buf = alignPtr(buf + blocksize*wsz, 16);
|
||||
wbuf = maskbuf = buf;
|
||||
if( cvtdst )
|
||||
buf = alignPtr(buf + blocksize*wsz, 16);
|
||||
{
|
||||
buf = alignPtr(buf + blocksize * wsz, 16);
|
||||
}
|
||||
if( haveMask )
|
||||
{
|
||||
maskbuf = buf;
|
||||
}
|
||||
|
||||
convertAndUnrollScalar( src2, wtype, buf2, blocksize);
|
||||
|
||||
@@ -860,34 +888,43 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
const uchar* sptr2 = buf2;
|
||||
uchar* dptr = ptrs[1];
|
||||
|
||||
if( cvtsrc1 )
|
||||
{
|
||||
cvtsrc1( sptr1, 1, 0, 1, buf1, 1, bszn, 0 );
|
||||
sptr1 = buf1;
|
||||
}
|
||||
|
||||
const uchar* extSptr1 = sptr1;
|
||||
const uchar* extSptr2 = sptr2;
|
||||
if( swapped12 )
|
||||
std::swap(sptr1, sptr2);
|
||||
std::swap(extSptr1, extSptr1);
|
||||
|
||||
if( !haveMask && !cvtdst )
|
||||
func( sptr1, 1, sptr2, 1, dptr, 1, bszn.width, bszn.height, usrdata );
|
||||
else
|
||||
// try to perform operation with conversion in one call
|
||||
// if fail, use converter functions
|
||||
uchar* opconverted = haveMask ? maskbuf : dptr;
|
||||
if (!extendedFunc || extendedFunc(extSptr1, 1, extSptr2, 1, opconverted, 1,
|
||||
bszn.width, bszn.height, usrdata) != 0)
|
||||
{
|
||||
func( sptr1, 1, sptr2, 1, wbuf, 1, bszn.width, bszn.height, usrdata );
|
||||
if( !haveMask )
|
||||
cvtdst( wbuf, 1, 0, 1, dptr, 1, bszn, 0 );
|
||||
else if( !cvtdst )
|
||||
if( cvtsrc1 )
|
||||
{
|
||||
copymask( wbuf, 1, ptrs[2], 1, dptr, 1, Size(bsz, 1), &dsz );
|
||||
ptrs[2] += bsz;
|
||||
cvtsrc1( sptr1, 1, 0, 1, buf1, 1, bszn, 0 );
|
||||
sptr1 = buf1;
|
||||
}
|
||||
else
|
||||
|
||||
if( swapped12 )
|
||||
std::swap(sptr1, sptr2);
|
||||
|
||||
uchar* fdst = ( haveMask || cvtdst ) ? wbuf : dptr;
|
||||
func( sptr1, 1, sptr2, 1, fdst, 1, bszn.width, bszn.height, usrdata );
|
||||
|
||||
if (cvtdst)
|
||||
{
|
||||
cvtdst( wbuf, 1, 0, 1, maskbuf, 1, bszn, 0 );
|
||||
copymask( maskbuf, 1, ptrs[2], 1, dptr, 1, Size(bsz, 1), &dsz );
|
||||
ptrs[2] += bsz;
|
||||
uchar* cdst = haveMask ? maskbuf : dptr;
|
||||
cvtdst(wbuf, 1, 0, 1, cdst, 1, bszn, 0);
|
||||
}
|
||||
opconverted = cvtdst ? maskbuf : wbuf;
|
||||
}
|
||||
|
||||
if (haveMask)
|
||||
{
|
||||
copymask(opconverted, 1, ptrs[2], 1, dptr, 1, Size(bsz, 1), &dsz);
|
||||
ptrs[2] += bsz;
|
||||
}
|
||||
|
||||
ptrs[0] += bsz*esz1; ptrs[1] += bsz*dsz;
|
||||
}
|
||||
}
|
||||
@@ -917,6 +954,32 @@ static BinaryFuncC* getAddTab()
|
||||
return addTab;
|
||||
}
|
||||
|
||||
static int sub8u32fWrapper(const uchar* src1, size_t step1, const uchar* src2, size_t step2,
|
||||
uchar* dst, size_t step, int width, int height, void* )
|
||||
{
|
||||
int res = cv_hal_sub8u32f(src1, step1, src2, step2, (float *)dst, step, width, height);
|
||||
if (res == CV_HAL_ERROR_OK || res == CV_HAL_ERROR_NOT_IMPLEMENTED)
|
||||
return res;
|
||||
else
|
||||
{
|
||||
CV_Error_(cv::Error::StsInternal, ("HAL implementation sub8u32f ==> " CVAUX_STR(cv_hal_sub8u32f)
|
||||
" returned %d (0x%08x)", res, res));
|
||||
}
|
||||
}
|
||||
|
||||
static int sub8s32fWrapper(const uchar* src1, size_t step1, const uchar* src2, size_t step2,
|
||||
uchar* dst, size_t step, int width, int height, void* )
|
||||
{
|
||||
int res = cv_hal_sub8s32f((schar*)src1, step1, (schar*)src2, step2, (float *)dst, step, width, height);
|
||||
if (res == CV_HAL_ERROR_OK || res == CV_HAL_ERROR_NOT_IMPLEMENTED)
|
||||
return res;
|
||||
else
|
||||
{
|
||||
CV_Error_(cv::Error::StsInternal, ("HAL implementation sub8s32f ==> " CVAUX_STR(cv_hal_sub8s32f)
|
||||
" returned %d (0x%08x)", res, res));
|
||||
}
|
||||
}
|
||||
|
||||
static BinaryFuncC* getSubTab()
|
||||
{
|
||||
static BinaryFuncC subTab[CV_DEPTH_MAX] =
|
||||
@@ -940,6 +1003,22 @@ static BinaryFuncC* getSubTab()
|
||||
return subTab;
|
||||
}
|
||||
|
||||
static ExtendedTypeFunc getSubExtFunc(int src1Type, int src2Type, int dstType)
|
||||
{
|
||||
if (src1Type == CV_8U && src2Type == CV_8U && dstType == CV_32F)
|
||||
{
|
||||
return sub8u32fWrapper;
|
||||
}
|
||||
else if (src1Type == CV_8S && src2Type == CV_8S && dstType == CV_32F)
|
||||
{
|
||||
return sub8s32fWrapper;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static BinaryFuncC* getAbsDiffTab()
|
||||
{
|
||||
static BinaryFuncC absDiffTab[CV_DEPTH_MAX] =
|
||||
@@ -974,11 +1053,13 @@ void cv::add( InputArray src1, InputArray src2, OutputArray dst,
|
||||
}
|
||||
|
||||
void cv::subtract( InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
InputArray mask, int dtype )
|
||||
InputArray mask, int dtype )
|
||||
{
|
||||
CV_INSTRUMENT_REGION();
|
||||
|
||||
arithm_op(_src1, _src2, _dst, mask, dtype, getSubTab(), false, 0, OCL_OP_SUB );
|
||||
ExtendedTypeFunc subExtFunc = getSubExtFunc(_src1.depth(), _src2.depth(), dtype < 0 ? _dst.depth() : dtype);
|
||||
arithm_op(_src1, _src2, _dst, mask, dtype, getSubTab(), false, 0, OCL_OP_SUB,
|
||||
/* extendedFunc */ subExtFunc);
|
||||
}
|
||||
|
||||
void cv::absdiff( InputArray src1, InputArray src2, OutputArray dst )
|
||||
@@ -1002,6 +1083,38 @@ void cv::copyTo(InputArray _src, OutputArray _dst, InputArray _mask)
|
||||
namespace cv
|
||||
{
|
||||
|
||||
static int mul8u16uWrapper(const uchar* src1, size_t step1,
|
||||
const uchar* src2, size_t step2,
|
||||
uchar* dst, size_t step, int width, int height,
|
||||
void* usrdata)
|
||||
{
|
||||
double scale = *((double*)usrdata);
|
||||
int res = cv_hal_mul8u16u(src1, step1, src2, step2, (ushort *)dst, step, width, height, scale);
|
||||
if (res == CV_HAL_ERROR_OK || res == CV_HAL_ERROR_NOT_IMPLEMENTED)
|
||||
return res;
|
||||
else
|
||||
{
|
||||
CV_Error_(cv::Error::StsInternal, ("HAL implementation mul8u16u ==> " CVAUX_STR(cv_hal_mul8u16u)
|
||||
" returned %d (0x%08x)", res, res));
|
||||
}
|
||||
}
|
||||
|
||||
static int mul8s16sWrapper(const uchar* src1, size_t step1,
|
||||
const uchar* src2, size_t step2,
|
||||
uchar* dst, size_t step, int width, int height,
|
||||
void* usrdata)
|
||||
{
|
||||
double scale = *((double*)usrdata);
|
||||
int res = cv_hal_mul8s16s((schar *)src1, step1, (schar *)src2, step2, (short *)dst, step, width, height, scale);
|
||||
if (res == CV_HAL_ERROR_OK || res == CV_HAL_ERROR_NOT_IMPLEMENTED)
|
||||
return res;
|
||||
else
|
||||
{
|
||||
CV_Error_(cv::Error::StsInternal, ("HAL implementation mul8s16s ==> " CVAUX_STR(cv_hal_mul8s16s)
|
||||
" returned %d (0x%08x)", res, res));
|
||||
}
|
||||
}
|
||||
|
||||
static BinaryFuncC* getMulTab()
|
||||
{
|
||||
static BinaryFuncC mulTab[CV_DEPTH_MAX] =
|
||||
@@ -1015,6 +1128,22 @@ static BinaryFuncC* getMulTab()
|
||||
return mulTab;
|
||||
}
|
||||
|
||||
static ExtendedTypeFunc getMulExtFunc(int src1Type, int src2Type, int dstType)
|
||||
{
|
||||
if (src1Type == CV_8U && src2Type == CV_8U && dstType == CV_16U)
|
||||
{
|
||||
return mul8u16uWrapper;
|
||||
}
|
||||
else if (src1Type == CV_8S && src2Type == CV_8S && dstType == CV_16S)
|
||||
{
|
||||
return mul8s16sWrapper;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static BinaryFuncC* getDivTab()
|
||||
{
|
||||
static BinaryFuncC divTab[CV_DEPTH_MAX] =
|
||||
@@ -1042,12 +1171,14 @@ static BinaryFuncC* getRecipTab()
|
||||
}
|
||||
|
||||
void multiply(InputArray src1, InputArray src2,
|
||||
OutputArray dst, double scale, int dtype)
|
||||
OutputArray dst, double scale, int dtype)
|
||||
{
|
||||
CV_INSTRUMENT_REGION();
|
||||
|
||||
ExtendedTypeFunc mulExtFunc = getMulExtFunc(src1.depth(), src2.depth(), dtype < 0 ? dst.depth() : dtype);
|
||||
arithm_op(src1, src2, dst, noArray(), dtype, getMulTab(),
|
||||
true, &scale, std::abs(scale - 1.0) < DBL_EPSILON ? OCL_OP_MUL : OCL_OP_MUL_SCALE);
|
||||
/* muldiv */ true, &scale, std::abs(scale - 1.0) < DBL_EPSILON ? OCL_OP_MUL : OCL_OP_MUL_SCALE,
|
||||
/* extendedFunc */ mulExtFunc );
|
||||
}
|
||||
|
||||
void divide(InputArray src1, InputArray src2,
|
||||
|
||||
@@ -148,6 +148,7 @@ void cv::mixChannels( const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, cons
|
||||
NAryMatIterator it(arrays, ptrs, (int)(nsrcs + ndsts));
|
||||
int total = (int)it.size, blocksize = std::min(total, (int)((BLOCK_SIZE + esz1-1)/esz1));
|
||||
MixChannelsFunc func = getMixchFunc(depth);
|
||||
CV_Assert(func);
|
||||
|
||||
for( i = 0; i < it.nplanes; i++, ++it )
|
||||
{
|
||||
|
||||
@@ -111,8 +111,18 @@ set_value(fptype *dst, size_t dst_ld, fptype value, size_t m, size_t n)
|
||||
template <typename fptype> static inline int
|
||||
lapack_LU(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n, int* info)
|
||||
{
|
||||
int lda = (int)(a_step / sizeof(fptype)), sign = 0;
|
||||
std::vector<int> piv(m+1);
|
||||
#if defined (ACCELERATE_NEW_LAPACK) && defined (ACCELERATE_LAPACK_ILP64)
|
||||
cv::AutoBuffer<long> piv_buff(m);
|
||||
long lda = (long)(a_step / sizeof(fptype));
|
||||
long _m = static_cast<long>(m), _n = static_cast<long>(n);
|
||||
long _info[1];
|
||||
#else
|
||||
cv::AutoBuffer<int> piv_buff(m);
|
||||
int lda = (int)(a_step / sizeof(fptype));
|
||||
int _m = m, _n = n;
|
||||
int* _info = info;
|
||||
#endif
|
||||
auto piv = piv_buff.data();
|
||||
|
||||
transpose_square_inplace(a, lda, m);
|
||||
|
||||
@@ -121,9 +131,9 @@ lapack_LU(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n, int*
|
||||
if(n == 1 && b_step == sizeof(fptype))
|
||||
{
|
||||
if(typeid(fptype) == typeid(float))
|
||||
sgesv_(&m, &n, (float*)a, &lda, &piv[0], (float*)b, &m, info);
|
||||
sgesv_(&_m, &_n, (float*)a, &lda, piv, (float*)b, &_m, _info);
|
||||
else if(typeid(fptype) == typeid(double))
|
||||
dgesv_(&m, &n, (double*)a, &lda, &piv[0], (double*)b, &m, info);
|
||||
dgesv_(&_m, &_n, (double*)a, &lda, piv, (double*)b, &_m, _info);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -133,9 +143,9 @@ lapack_LU(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n, int*
|
||||
transpose(b, ldb, &tmpB[0], m, m, n);
|
||||
|
||||
if(typeid(fptype) == typeid(float))
|
||||
sgesv_(&m, &n, (float*)a, &lda, &piv[0], (float*)&tmpB[0], &m, info);
|
||||
sgesv_(&_m, &_n, (float*)a, &lda, piv, (float*)&tmpB[0], &_m, _info);
|
||||
else if(typeid(fptype) == typeid(double))
|
||||
dgesv_(&m, &n, (double*)a, &lda, &piv[0], (double*)&tmpB[0], &m, info);
|
||||
dgesv_(&_m, &_n, (double*)a, &lda, piv, (double*)&tmpB[0], &_m, _info);
|
||||
|
||||
transpose(&tmpB[0], m, b, ldb, n, m);
|
||||
}
|
||||
@@ -143,13 +153,17 @@ lapack_LU(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n, int*
|
||||
else
|
||||
{
|
||||
if(typeid(fptype) == typeid(float))
|
||||
sgetrf_(&m, &m, (float*)a, &lda, &piv[0], info);
|
||||
sgetrf_(&_m, &_m, (float*)a, &lda, piv, _info);
|
||||
else if(typeid(fptype) == typeid(double))
|
||||
dgetrf_(&m, &m, (double*)a, &lda, &piv[0], info);
|
||||
dgetrf_(&_m, &_m, (double*)a, &lda, piv, _info);
|
||||
}
|
||||
|
||||
#if defined (ACCELERATE_NEW_LAPACK) && defined (ACCELERATE_LAPACK_ILP64)
|
||||
*info = static_cast<int>(_info[0]);
|
||||
#endif
|
||||
int retcode = *info >= 0 ? CV_HAL_ERROR_OK : CV_HAL_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
int sign = 0;
|
||||
if(*info == 0)
|
||||
{
|
||||
for(int i = 0; i < m; i++)
|
||||
@@ -165,8 +179,15 @@ lapack_LU(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n, int*
|
||||
template <typename fptype> static inline int
|
||||
lapack_Cholesky(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n, bool* info)
|
||||
{
|
||||
#if defined (ACCELERATE_NEW_LAPACK) && defined (ACCELERATE_LAPACK_ILP64)
|
||||
long _m = static_cast<long>(m), _n = static_cast<long>(n);
|
||||
long lapackStatus = 0;
|
||||
long lda = (long)(a_step / sizeof(fptype));
|
||||
#else
|
||||
int _m = m, _n = n;
|
||||
int lapackStatus = 0;
|
||||
int lda = (int)(a_step / sizeof(fptype));
|
||||
#endif
|
||||
char L[] = {'L', '\0'};
|
||||
|
||||
if(b)
|
||||
@@ -174,9 +195,9 @@ lapack_Cholesky(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n
|
||||
if(n == 1 && b_step == sizeof(fptype))
|
||||
{
|
||||
if(typeid(fptype) == typeid(float))
|
||||
OCV_LAPACK_FUNC(sposv)(L, &m, &n, (float*)a, &lda, (float*)b, &m, &lapackStatus);
|
||||
OCV_LAPACK_FUNC(sposv)(L, &_m, &_n, (float*)a, &lda, (float*)b, &_m, &lapackStatus);
|
||||
else if(typeid(fptype) == typeid(double))
|
||||
OCV_LAPACK_FUNC(dposv)(L, &m, &n, (double*)a, &lda, (double*)b, &m, &lapackStatus);
|
||||
OCV_LAPACK_FUNC(dposv)(L, &_m, &_n, (double*)a, &lda, (double*)b, &_m, &lapackStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -185,9 +206,9 @@ lapack_Cholesky(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n
|
||||
transpose(b, ldb, tmpB, m, m, n);
|
||||
|
||||
if(typeid(fptype) == typeid(float))
|
||||
OCV_LAPACK_FUNC(sposv)(L, &m, &n, (float*)a, &lda, (float*)tmpB, &m, &lapackStatus);
|
||||
OCV_LAPACK_FUNC(sposv)(L, &_m, &_n, (float*)a, &lda, (float*)tmpB, &_m, &lapackStatus);
|
||||
else if(typeid(fptype) == typeid(double))
|
||||
OCV_LAPACK_FUNC(dposv)(L, &m, &n, (double*)a, &lda, (double*)tmpB, &m, &lapackStatus);
|
||||
OCV_LAPACK_FUNC(dposv)(L, &_m, &_n, (double*)a, &lda, (double*)tmpB, &_m, &lapackStatus);
|
||||
|
||||
transpose(tmpB, m, b, ldb, n, m);
|
||||
delete[] tmpB;
|
||||
@@ -196,9 +217,9 @@ lapack_Cholesky(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n
|
||||
else
|
||||
{
|
||||
if(typeid(fptype) == typeid(float))
|
||||
OCV_LAPACK_FUNC(spotrf)(L, &m, (float*)a, &lda, &lapackStatus);
|
||||
OCV_LAPACK_FUNC(spotrf)(L, &_m, (float*)a, &lda, &lapackStatus);
|
||||
else if(typeid(fptype) == typeid(double))
|
||||
OCV_LAPACK_FUNC(dpotrf)(L, &m, (double*)a, &lda, &lapackStatus);
|
||||
OCV_LAPACK_FUNC(dpotrf)(L, &_m, (double*)a, &lda, &lapackStatus);
|
||||
}
|
||||
|
||||
if(lapackStatus == 0) *info = true;
|
||||
@@ -210,11 +231,24 @@ lapack_Cholesky(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n
|
||||
template <typename fptype> static inline int
|
||||
lapack_SVD(fptype* a, size_t a_step, fptype *w, fptype* u, size_t u_step, fptype* vt, size_t v_step, int m, int n, int flags, int* info)
|
||||
{
|
||||
#if defined (ACCELERATE_NEW_LAPACK) && defined (ACCELERATE_LAPACK_ILP64)
|
||||
long _m = static_cast<long>(m), _n = static_cast<long>(n);
|
||||
long _info[1];
|
||||
long lda = (long)(a_step / sizeof(fptype));
|
||||
long ldv = (long)(v_step / sizeof(fptype));
|
||||
long ldu = (long)(u_step / sizeof(fptype));
|
||||
long lwork = -1;
|
||||
cv::AutoBuffer<long> iworkBuf_(8 * std::min(m, n));
|
||||
#else
|
||||
int _m = m, _n = n;
|
||||
int* _info = info;
|
||||
int lda = (int)(a_step / sizeof(fptype));
|
||||
int ldv = (int)(v_step / sizeof(fptype));
|
||||
int ldu = (int)(u_step / sizeof(fptype));
|
||||
int lwork = -1;
|
||||
std::vector<int> iworkBuf(8*std::min(m, n));
|
||||
cv::AutoBuffer<int> iworkBuf_(8 * std::min(m, n));
|
||||
#endif
|
||||
auto iworkBuf = iworkBuf_.data();
|
||||
std::vector<fptype> ubuf;
|
||||
fptype work1 = 0;
|
||||
|
||||
@@ -240,11 +274,9 @@ lapack_SVD(fptype* a, size_t a_step, fptype *w, fptype* u, size_t u_step, fptype
|
||||
}
|
||||
|
||||
if(typeid(fptype) == typeid(float))
|
||||
OCV_LAPACK_FUNC(sgesdd)(mode, &m, &n, (float*)a, &lda, (float*)w, (float*)u, &ldu,
|
||||
(float*)vt, &ldv, (float*)&work1, &lwork, &iworkBuf[0], info);
|
||||
OCV_LAPACK_FUNC(sgesdd)(mode, &_m, &_n, (float*)a, &lda, (float*)w, (float*)u, &ldu, (float*)vt, &ldv, (float*)&work1, &lwork, iworkBuf, _info);
|
||||
else if(typeid(fptype) == typeid(double))
|
||||
OCV_LAPACK_FUNC(dgesdd)(mode, &m, &n, (double*)a, &lda, (double*)w, (double*)u, &ldu,
|
||||
(double*)vt, &ldv, (double*)&work1, &lwork, &iworkBuf[0], info);
|
||||
OCV_LAPACK_FUNC(dgesdd)(mode, &_m, &_n, (double*)a, &lda, (double*)w, (double*)u, &ldu, (double*)vt, &ldv, (double*)&work1, &lwork, iworkBuf, _info);
|
||||
|
||||
if(*info < 0)
|
||||
return CV_HAL_ERROR_NOT_IMPLEMENTED;
|
||||
@@ -258,11 +290,13 @@ lapack_SVD(fptype* a, size_t a_step, fptype *w, fptype* u, size_t u_step, fptype
|
||||
CV_ANNOTATE_MEMORY_IS_INITIALIZED(buffer.data(), sizeof(fptype) * (lwork + 1));
|
||||
|
||||
if(typeid(fptype) == typeid(float))
|
||||
OCV_LAPACK_FUNC(sgesdd)(mode, &m, &n, (float*)a, &lda, (float*)w, (float*)u, &ldu,
|
||||
(float*)vt, &ldv, (float*)&buffer[0], &lwork, &iworkBuf[0], info);
|
||||
OCV_LAPACK_FUNC(sgesdd)(mode, &_m, &_n, (float*)a, &lda, (float*)w, (float*)u, &ldu, (float*)vt, &ldv, (float*)&buffer[0], &lwork, iworkBuf, _info);
|
||||
else if(typeid(fptype) == typeid(double))
|
||||
OCV_LAPACK_FUNC(dgesdd)(mode, &m, &n, (double*)a, &lda, (double*)w, (double*)u, &ldu,
|
||||
(double*)vt, &ldv, (double*)&buffer[0], &lwork, &iworkBuf[0], info);
|
||||
OCV_LAPACK_FUNC(dgesdd)(mode, &_m, &_n, (double*)a, &lda, (double*)w, (double*)u, &ldu, (double*)vt, &ldv, (double*)&buffer[0], &lwork, iworkBuf, _info);
|
||||
|
||||
#if defined (ACCELERATE_NEW_LAPACK) && defined (ACCELERATE_LAPACK_ILP64)
|
||||
*info = static_cast<int>(_info[0]);
|
||||
#endif
|
||||
|
||||
// Make sure MSAN sees the memory as having been written.
|
||||
// MSAN does not think it has been written because a different language was called.
|
||||
@@ -292,14 +326,27 @@ lapack_SVD(fptype* a, size_t a_step, fptype *w, fptype* u, size_t u_step, fptype
|
||||
template <typename fptype> static inline int
|
||||
lapack_QR(fptype* a, size_t a_step, int m, int n, int k, fptype* b, size_t b_step, fptype* dst, int* info)
|
||||
{
|
||||
#if defined (ACCELERATE_NEW_LAPACK) && defined (ACCELERATE_LAPACK_ILP64)
|
||||
long _m = static_cast<long>(m), _n = static_cast<long>(n), _k = static_cast<long>(k);
|
||||
long _info[1];
|
||||
long lda = (long)(a_step / sizeof(fptype));
|
||||
long lwork = -1;
|
||||
long ldtmpA;
|
||||
#else
|
||||
int _m = m, _n = n, _k = k;
|
||||
int* _info = info;
|
||||
int lda = (int)(a_step / sizeof(fptype));
|
||||
int lwork = -1;
|
||||
int ldtmpA;
|
||||
#endif
|
||||
|
||||
char mode[] = { 'N', '\0' };
|
||||
if(m < n)
|
||||
return CV_HAL_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
std::vector<fptype> tmpAMemHolder;
|
||||
fptype* tmpA;
|
||||
int ldtmpA;
|
||||
|
||||
if (m == n)
|
||||
{
|
||||
transpose_square_inplace(a, lda, m);
|
||||
@@ -314,7 +361,6 @@ lapack_QR(fptype* a, size_t a_step, int m, int n, int k, fptype* b, size_t b_ste
|
||||
transpose(a, lda, tmpA, m, m, n);
|
||||
}
|
||||
|
||||
int lwork = -1;
|
||||
fptype work1 = 0.;
|
||||
|
||||
if (b)
|
||||
@@ -322,9 +368,9 @@ lapack_QR(fptype* a, size_t a_step, int m, int n, int k, fptype* b, size_t b_ste
|
||||
if (k == 1 && b_step == sizeof(fptype))
|
||||
{
|
||||
if (typeid(fptype) == typeid(float))
|
||||
OCV_LAPACK_FUNC(sgels)(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)b, &m, (float*)&work1, &lwork, info);
|
||||
OCV_LAPACK_FUNC(sgels)(mode, &_m, &_n, &_k, (float*)tmpA, &ldtmpA, (float*)b, &_m, (float*)&work1, &lwork, _info);
|
||||
else if (typeid(fptype) == typeid(double))
|
||||
OCV_LAPACK_FUNC(dgels)(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)b, &m, (double*)&work1, &lwork, info);
|
||||
OCV_LAPACK_FUNC(dgels)(mode, &_m, &_n, &_k, (double*)tmpA, &ldtmpA, (double*)b, &_m, (double*)&work1, &lwork, _info);
|
||||
|
||||
if (*info < 0)
|
||||
return CV_HAL_ERROR_NOT_IMPLEMENTED;
|
||||
@@ -334,9 +380,9 @@ lapack_QR(fptype* a, size_t a_step, int m, int n, int k, fptype* b, size_t b_ste
|
||||
fptype* buffer = &workBufMemHolder.front();
|
||||
|
||||
if (typeid(fptype) == typeid(float))
|
||||
OCV_LAPACK_FUNC(sgels)(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)b, &m, (float*)buffer, &lwork, info);
|
||||
OCV_LAPACK_FUNC(sgels)(mode, &_m, &_n, &_k, (float*)tmpA, &ldtmpA, (float*)b, &_m, (float*)buffer, &lwork, _info);
|
||||
else if (typeid(fptype) == typeid(double))
|
||||
OCV_LAPACK_FUNC(dgels)(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)b, &m, (double*)buffer, &lwork, info);
|
||||
OCV_LAPACK_FUNC(dgels)(mode, &_m, &_n, &_k, (double*)tmpA, &ldtmpA, (double*)b, &_m, (double*)buffer, &lwork, _info);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -346,9 +392,9 @@ lapack_QR(fptype* a, size_t a_step, int m, int n, int k, fptype* b, size_t b_ste
|
||||
transpose(b, ldb, tmpB, m, m, k);
|
||||
|
||||
if (typeid(fptype) == typeid(float))
|
||||
OCV_LAPACK_FUNC(sgels)(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)tmpB, &m, (float*)&work1, &lwork, info);
|
||||
OCV_LAPACK_FUNC(sgels)(mode, &_m, &_n, &_k, (float*)tmpA, &ldtmpA, (float*)tmpB, &_m, (float*)&work1, &lwork, _info);
|
||||
else if (typeid(fptype) == typeid(double))
|
||||
OCV_LAPACK_FUNC(dgels)(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)tmpB, &m, (double*)&work1, &lwork, info);
|
||||
OCV_LAPACK_FUNC(dgels)(mode, &_m, &_n, &_k, (double*)tmpA, &ldtmpA, (double*)tmpB, &_m, (double*)&work1, &lwork, _info);
|
||||
|
||||
if (*info < 0)
|
||||
return CV_HAL_ERROR_NOT_IMPLEMENTED;
|
||||
@@ -358,9 +404,9 @@ lapack_QR(fptype* a, size_t a_step, int m, int n, int k, fptype* b, size_t b_ste
|
||||
fptype* buffer = &workBufMemHolder.front();
|
||||
|
||||
if (typeid(fptype) == typeid(float))
|
||||
OCV_LAPACK_FUNC(sgels)(mode, &m, &n, &k, (float*)tmpA, &ldtmpA, (float*)tmpB, &m, (float*)buffer, &lwork, info);
|
||||
OCV_LAPACK_FUNC(sgels)(mode, &_m, &_n, &_k, (float*)tmpA, &ldtmpA, (float*)tmpB, &_m, (float*)buffer, &lwork, _info);
|
||||
else if (typeid(fptype) == typeid(double))
|
||||
OCV_LAPACK_FUNC(dgels)(mode, &m, &n, &k, (double*)tmpA, &ldtmpA, (double*)tmpB, &m, (double*)buffer, &lwork, info);
|
||||
OCV_LAPACK_FUNC(dgels)(mode, &_m, &_n, &_k, (double*)tmpA, &ldtmpA, (double*)tmpB, &_m, (double*)buffer, &lwork, _info);
|
||||
|
||||
transpose(tmpB, m, b, ldb, k, m);
|
||||
}
|
||||
@@ -368,9 +414,9 @@ lapack_QR(fptype* a, size_t a_step, int m, int n, int k, fptype* b, size_t b_ste
|
||||
else
|
||||
{
|
||||
if (typeid(fptype) == typeid(float))
|
||||
sgeqrf_(&m, &n, (float*)tmpA, &ldtmpA, (float*)dst, (float*)&work1, &lwork, info);
|
||||
sgeqrf_(&_m, &_n, (float*)tmpA, &ldtmpA, (float*)dst, (float*)&work1, &lwork, _info);
|
||||
else if (typeid(fptype) == typeid(double))
|
||||
dgeqrf_(&m, &n, (double*)tmpA, &ldtmpA, (double*)dst, (double*)&work1, &lwork, info);
|
||||
dgeqrf_(&_m, &_n, (double*)tmpA, &ldtmpA, (double*)dst, (double*)&work1, &lwork, _info);
|
||||
|
||||
if (*info < 0)
|
||||
return CV_HAL_ERROR_NOT_IMPLEMENTED;
|
||||
@@ -380,9 +426,9 @@ lapack_QR(fptype* a, size_t a_step, int m, int n, int k, fptype* b, size_t b_ste
|
||||
fptype* buffer = &workBufMemHolder.front();
|
||||
|
||||
if (typeid(fptype) == typeid(float))
|
||||
sgeqrf_(&m, &n, (float*)tmpA, &ldtmpA, (float*)dst, (float*)buffer, &lwork, info);
|
||||
sgeqrf_(&_m, &_n, (float*)tmpA, &ldtmpA, (float*)dst, (float*)buffer, &lwork, _info);
|
||||
else if (typeid(fptype) == typeid(double))
|
||||
dgeqrf_(&m, &n, (double*)tmpA, &ldtmpA, (double*)dst, (double*)buffer, &lwork, info);
|
||||
dgeqrf_(&_m, &_n, (double*)tmpA, &ldtmpA, (double*)dst, (double*)buffer, &lwork, _info);
|
||||
}
|
||||
|
||||
CV_ANNOTATE_MEMORY_IS_INITIALIZED(info, sizeof(int));
|
||||
@@ -391,6 +437,10 @@ lapack_QR(fptype* a, size_t a_step, int m, int n, int k, fptype* b, size_t b_ste
|
||||
else
|
||||
transpose(tmpA, m, a, lda, n, m);
|
||||
|
||||
#if defined (ACCELERATE_NEW_LAPACK) && defined (ACCELERATE_LAPACK_ILP64)
|
||||
*info = static_cast<int>(_info[0]);
|
||||
#endif
|
||||
|
||||
if (*info != 0)
|
||||
*info = 0;
|
||||
else
|
||||
@@ -475,7 +525,6 @@ lapack_gemm(const fptype *src1, size_t src1_step, const fptype *src2, size_t src
|
||||
return CV_HAL_ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
template <typename fptype> static inline int
|
||||
lapack_gemm_c(const fptype *src1, size_t src1_step, const fptype *src2, size_t src2_step, fptype alpha,
|
||||
const fptype *src3, size_t src3_step, fptype beta, fptype *dst, size_t dst_step, int a_m, int a_n, int d_n, int flags)
|
||||
@@ -546,10 +595,29 @@ lapack_gemm_c(const fptype *src1, size_t src1_step, const fptype *src2, size_t s
|
||||
else if(src3_step == 0 && beta != 0.0)
|
||||
set_value((std::complex<fptype>*)dst, lddst, std::complex<fptype>(0.0, 0.0), d_m, d_n);
|
||||
|
||||
// FIXME: this is a workaround. Support ILP64 in HAL API.
|
||||
#if defined (ACCELERATE_NEW_LAPACK) && defined (ACCELERATE_LAPACK_ILP64)
|
||||
int M = a_m, N = d_n, K = a_n;
|
||||
if(typeid(fptype) == typeid(float)) {
|
||||
auto src1_cast = (std::complex<float>*)(src1);
|
||||
auto src2_cast = (std::complex<float>*)(src2);
|
||||
auto dst_cast = (std::complex<float>*)(dst);
|
||||
long lda = ldsrc1, ldb = ldsrc2, ldc = lddst;
|
||||
cblas_cgemm(CblasRowMajor, transA, transB, M, N, K, (std::complex<float>*)&cAlpha, src1_cast, lda, src2_cast, ldb, (std::complex<float>*)&cBeta, dst_cast, ldc);
|
||||
}
|
||||
else if(typeid(fptype) == typeid(double)) {
|
||||
auto src1_cast = (std::complex<double>*)(src1);
|
||||
auto src2_cast = (std::complex<double>*)(src2);
|
||||
auto dst_cast = (std::complex<double>*)(dst);
|
||||
long lda = ldsrc1, ldb = ldsrc2, ldc = lddst;
|
||||
cblas_zgemm(CblasRowMajor, transA, transB, M, N, K, (std::complex<double>*)&cAlpha, src1_cast, lda, src2_cast, ldb, (std::complex<double>*)&cBeta, dst_cast, ldc);
|
||||
}
|
||||
#else
|
||||
if(typeid(fptype) == typeid(float))
|
||||
cblas_cgemm(CblasRowMajor, transA, transB, a_m, d_n, a_n, (float*)reinterpret_cast<fptype(&)[2]>(cAlpha), (float*)src1, ldsrc1, (float*)src2, ldsrc2, (float*)reinterpret_cast<fptype(&)[2]>(cBeta), (float*)dst, lddst);
|
||||
else if(typeid(fptype) == typeid(double))
|
||||
cblas_zgemm(CblasRowMajor, transA, transB, a_m, d_n, a_n, (double*)reinterpret_cast<fptype(&)[2]>(cAlpha), (double*)src1, ldsrc1, (double*)src2, ldsrc2, (double*)reinterpret_cast<fptype(&)[2]>(cBeta), (double*)dst, lddst);
|
||||
#endif
|
||||
|
||||
return CV_HAL_ERROR_OK;
|
||||
}
|
||||
|
||||
@@ -106,6 +106,10 @@ inline int hal_ni_sub64s(const int64 *src1_data, size_t src1_step, const int64 *
|
||||
inline int hal_ni_sub16f(const cv_hal_f16 *src1_data, size_t src1_step, const cv_hal_f16 *src2_data, size_t src2_step, cv_hal_f16 *dst_data, size_t dst_step, int width, int height) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
inline int hal_ni_sub16bf(const cv_hal_bf16 *src1_data, size_t src1_step, const cv_hal_bf16 *src2_data, size_t src2_step, cv_hal_bf16 *dst_data, size_t dst_step, int width, int height) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
|
||||
inline int hal_ni_sub8u32f(const uchar *src1_data, size_t src1_step, const uchar *src2_data, size_t src2_step, float *dst_data, size_t dst_step, int width, int height) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
inline int hal_ni_sub8s32f(const schar *src1_data, size_t src1_step, const schar *src2_data, size_t src2_step, float *dst_data, size_t dst_step, int width, int height) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
/**
|
||||
@@ -221,6 +225,8 @@ inline int hal_ni_not8u(const uchar *src_data, size_t src_step, uchar *dst_data,
|
||||
#define cv_hal_sub64s hal_ni_sub64s
|
||||
#define cv_hal_sub32f hal_ni_sub32f
|
||||
#define cv_hal_sub64f hal_ni_sub64f
|
||||
#define cv_hal_sub8u32f hal_ni_sub8u32f
|
||||
#define cv_hal_sub8s32f hal_ni_sub8s32f
|
||||
#define cv_hal_sub16f hal_ni_sub16f
|
||||
#define cv_hal_sub16bf hal_ni_sub16bf
|
||||
#define cv_hal_max8u hal_ni_max8u
|
||||
@@ -265,6 +271,62 @@ inline int hal_ni_not8u(const uchar *src_data, size_t src_step, uchar *dst_data,
|
||||
#define cv_hal_not8u hal_ni_not8u
|
||||
//! @endcond
|
||||
|
||||
/**
|
||||
Lookup table replacement
|
||||
Table consists of 256 elements of a size from 1 to 8 bytes having 1 channel or src_channels
|
||||
For 8s input type 128 is added to LUT index
|
||||
Destination should have the same element type and number of channels as lookup table elements
|
||||
@param src_data Source image data
|
||||
@param src_step Source image step
|
||||
@param src_type Sorce image type
|
||||
@param lut_data Pointer to lookup table
|
||||
@param lut_channel_size Size of each channel in bytes
|
||||
@param lut_channels Number of channels in lookup table
|
||||
@param dst_data Destination data
|
||||
@param dst_step Destination step
|
||||
@param width Width of images
|
||||
@param height Height of images
|
||||
@sa LUT
|
||||
*/
|
||||
//! @addtogroup core_hal_interface_lut Lookup table
|
||||
//! @{
|
||||
inline int hal_ni_lut(const uchar *src_data, size_t src_step, size_t src_type, const uchar* lut_data, size_t lut_channel_size, size_t lut_channels, uchar *dst_data, size_t dst_step, int width, int height) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
//! @}
|
||||
|
||||
//! @cond IGNORED
|
||||
#define cv_hal_lut hal_ni_lut
|
||||
//! @endcond
|
||||
|
||||
/**
|
||||
Hamming norm of a vector
|
||||
@param a pointer to vector data
|
||||
@param n length of a vector
|
||||
@param cellSize how many bits of the vector will be added and treated as a single bit, can be 1 (standard Hamming distance), 2 or 4
|
||||
@param result pointer to result output
|
||||
*/
|
||||
//! @addtogroup core_hal_interface_hamming Hamming distance
|
||||
//! @{
|
||||
inline int hal_ni_normHamming8u(const uchar* a, int n, int cellSize, int* result) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
//! @}
|
||||
|
||||
/**
|
||||
Hamming distance between two vectors
|
||||
@param a pointer to first vector data
|
||||
@param b pointer to second vector data
|
||||
@param n length of vectors
|
||||
@param cellSize how many bits of the vectors will be added and treated as a single bit, can be 1 (standard Hamming distance), 2 or 4
|
||||
@param result pointer to result output
|
||||
*/
|
||||
//! @addtogroup core_hal_interface_hamming Hamming distance
|
||||
//! @{
|
||||
inline int hal_ni_normHammingDiff8u(const uchar* a, const uchar* b, int n, int cellSize, int* result) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
//! @}
|
||||
|
||||
//! @cond IGNORED
|
||||
#define cv_hal_normHamming8u hal_ni_normHamming8u
|
||||
#define cv_hal_normHammingDiff8u hal_ni_normHammingDiff8u
|
||||
//! @endcond
|
||||
|
||||
/**
|
||||
Compare: _dst[i] = src1[i] op src2[i]_
|
||||
@param src1_data first source image data
|
||||
@@ -330,6 +392,8 @@ inline int hal_ni_mul32u(const unsigned *src1_data, size_t src1_step, const unsi
|
||||
inline int hal_ni_mul32s(const int *src1_data, size_t src1_step, const int *src2_data, size_t src2_step, int *dst_data, size_t dst_step, int width, int height, double scale) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
inline int hal_ni_mul32f(const float *src1_data, size_t src1_step, const float *src2_data, size_t src2_step, float *dst_data, size_t dst_step, int width, int height, double scale) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
inline int hal_ni_mul64f(const double *src1_data, size_t src1_step, const double *src2_data, size_t src2_step, double *dst_data, size_t dst_step, int width, int height, double scale) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
inline int hal_ni_mul8u16u(const uchar* src1_data, size_t src1_step, const uchar* src2_data, size_t src2_step, ushort* dst_data, size_t dst_step, int width, int height, double scale) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
inline int hal_ni_mul8s16s(const schar* src1_data, size_t src1_step, const schar* src2_data, size_t src2_step, short* dst_data, size_t dst_step, int width, int height, double scale) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
inline int hal_ni_mul64u(const uint64 *src1_data, size_t src1_step, const uint64 *src2_data, size_t src2_step, uint64 *dst_data, size_t dst_step, int width, int height, double scale) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
inline int hal_ni_mul64s(const int64 *src1_data, size_t src1_step, const int64 *src2_data, size_t src2_step, int64 *dst_data, size_t dst_step, int width, int height, double scale) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
inline int hal_ni_mul16f(const cv_hal_f16 *src1_data, size_t src1_step, const cv_hal_f16 *src2_data, size_t src2_step, cv_hal_f16 *dst_data, size_t dst_step, int width, int height, double scale) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
@@ -401,6 +465,8 @@ inline int hal_ni_recip16bf(const cv_hal_bf16 *src_data, size_t src_step, cv_hal
|
||||
#define cv_hal_mul64s hal_ni_mul64s
|
||||
#define cv_hal_mul32f hal_ni_mul32f
|
||||
#define cv_hal_mul64f hal_ni_mul64f
|
||||
#define cv_hal_mul8u16u hal_ni_mul8u16u
|
||||
#define cv_hal_mul8s16s hal_ni_mul8s16s
|
||||
#define cv_hal_mul16f hal_ni_mul16f
|
||||
#define cv_hal_mul16bf hal_ni_mul16bf
|
||||
#define cv_hal_div8u hal_ni_div8u
|
||||
@@ -914,6 +980,27 @@ inline int hal_ni_minMaxIdx(const uchar* src_data, size_t src_step, int width, i
|
||||
#define cv_hal_minMaxIdx hal_ni_minMaxIdx
|
||||
//! @endcond
|
||||
|
||||
/**
|
||||
@brief calculates the mean and the standard deviation of array elements independently for each channel
|
||||
@param src_data Source image
|
||||
@param src_step Source image
|
||||
@param width Source image dimensions
|
||||
@param height Source image dimensions
|
||||
@param src_type Type of source image
|
||||
@param mean_val Array of per-channel mean values. May be nullptr, if mean value is not required.
|
||||
@param stddev_val Array of per-channel standard deviation values. May be nullptr, if stddev value is not required.
|
||||
@param mask Specified array region.
|
||||
@param mask_step Mask array step.
|
||||
@sa meanStdDev
|
||||
*/
|
||||
inline int hal_ni_meanStdDev(const uchar* src_data, size_t src_step, int width, int height,
|
||||
int src_type, double* mean_val, double* stddev_val, uchar* mask, size_t mask_step)
|
||||
{ return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
|
||||
//! @cond IGNORED
|
||||
#define cv_hal_meanStdDev hal_ni_meanStdDev
|
||||
//! @endcond
|
||||
|
||||
/**
|
||||
@brief hal_flip
|
||||
@param src_type source and destination image type
|
||||
|
||||
@@ -296,7 +296,7 @@ public:
|
||||
|
||||
void operator()( const cv::Range& range ) const CV_OVERRIDE
|
||||
{
|
||||
CV_DbgAssert(*ok);
|
||||
CV_Assert(*ok);
|
||||
|
||||
const int row0 = range.start;
|
||||
const int row1 = range.end;
|
||||
@@ -341,6 +341,9 @@ void cv::LUT( InputArray _src, InputArray _lut, OutputArray _dst )
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
|
||||
CALL_HAL(LUT, cv_hal_lut, src.data, src.step, src.type(), lut.data,
|
||||
lut.elemSize1(), lutcn, dst.data, dst.step, src.cols, src.rows);
|
||||
|
||||
#if !IPP_DISABLE_PERF_LUT
|
||||
CV_IPP_RUN(_src.dims() <= 2, ipp_lut(src, lut, dst));
|
||||
#endif
|
||||
|
||||
@@ -37,7 +37,7 @@ typedef void (*ConvertScaleData)(const void* from, void* to, int cn, double alph
|
||||
|
||||
static ConvertData getConvertElem(int fromType, int toType)
|
||||
{
|
||||
static ConvertData tab[][8] =
|
||||
static ConvertData tab[CV_DEPTH_MAX][CV_DEPTH_MAX] =
|
||||
{{ convertData_<uchar, uchar>, convertData_<uchar, schar>,
|
||||
convertData_<uchar, ushort>, convertData_<uchar, short>,
|
||||
convertData_<uchar, int>, convertData_<uchar, float>,
|
||||
@@ -82,7 +82,7 @@ static ConvertData getConvertElem(int fromType, int toType)
|
||||
|
||||
static ConvertScaleData getConvertScaleElem(int fromType, int toType)
|
||||
{
|
||||
static ConvertScaleData tab[][8] =
|
||||
static ConvertScaleData tab[CV_DEPTH_MAX][CV_DEPTH_MAX] =
|
||||
{{ convertScaleData_<uchar, uchar>, convertScaleData_<uchar, schar>,
|
||||
convertScaleData_<uchar, ushort>, convertScaleData_<uchar, short>,
|
||||
convertScaleData_<uchar, int>, convertScaleData_<uchar, float>,
|
||||
@@ -389,6 +389,7 @@ void SparseMat::convertTo( SparseMat& m, int rtype, double alpha ) const
|
||||
if( alpha == 1 )
|
||||
{
|
||||
ConvertData cvtfunc = getConvertElem(type(), rtype);
|
||||
CV_Assert(cvtfunc);
|
||||
for( size_t i = 0; i < N; i++, ++from )
|
||||
{
|
||||
const Node* n = from.node();
|
||||
@@ -399,6 +400,7 @@ void SparseMat::convertTo( SparseMat& m, int rtype, double alpha ) const
|
||||
else
|
||||
{
|
||||
ConvertScaleData cvtfunc = getConvertScaleElem(type(), rtype);
|
||||
CV_Assert(cvtfunc);
|
||||
for( size_t i = 0; i < N; i++, ++from )
|
||||
{
|
||||
const Node* n = from.node();
|
||||
|
||||
@@ -468,9 +468,52 @@ void meanStdDev(InputArray _src, OutputArray _mean, OutputArray _sdv, InputArray
|
||||
|
||||
Mat src = _src.getMat(), mask = _mask.getMat();
|
||||
|
||||
CV_Assert(mask.empty() || src.size == mask.size);
|
||||
|
||||
CV_IPP_RUN(IPP_VERSION_X100 >= 700, ipp_meanStdDev(src, _mean, _sdv, mask));
|
||||
|
||||
int k, cn = src.channels(), depth = src.depth();
|
||||
Mat mean_mat, stddev_mat;
|
||||
|
||||
if(_mean.needed())
|
||||
{
|
||||
if( !_mean.fixedSize() )
|
||||
_mean.create(cn, 1, CV_64F, -1, true);
|
||||
|
||||
mean_mat = _mean.getMat();
|
||||
int dcn = (int)mean_mat.total();
|
||||
CV_Assert( mean_mat.type() == CV_64F && mean_mat.isContinuous() &&
|
||||
(mean_mat.cols == 1 || mean_mat.rows == 1) && dcn >= cn );
|
||||
}
|
||||
|
||||
if (_sdv.needed())
|
||||
{
|
||||
if( !_sdv.fixedSize() )
|
||||
_sdv.create(cn, 1, CV_64F, -1, true);
|
||||
|
||||
stddev_mat = _sdv.getMat();
|
||||
int dcn = (int)stddev_mat.total();
|
||||
CV_Assert( stddev_mat.type() == CV_64F && stddev_mat.isContinuous() &&
|
||||
(stddev_mat.cols == 1 || stddev_mat.rows == 1) && dcn >= cn );
|
||||
}
|
||||
|
||||
if (src.isContinuous() && mask.isContinuous())
|
||||
{
|
||||
CALL_HAL(meanStdDev, cv_hal_meanStdDev, src.data, 0, (int)src.total(), 1, src.type(),
|
||||
_mean.needed() ? mean_mat.ptr<double>() : nullptr,
|
||||
_sdv.needed() ? stddev_mat.ptr<double>() : nullptr,
|
||||
mask.data, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (src.dims <= 2)
|
||||
{
|
||||
CALL_HAL(meanStdDev, cv_hal_meanStdDev, src.data, src.step, src.cols, src.rows, src.type(),
|
||||
_mean.needed() ? mean_mat.ptr<double>() : nullptr,
|
||||
_sdv.needed() ? stddev_mat.ptr<double>() : nullptr,
|
||||
mask.data, mask.step);
|
||||
}
|
||||
}
|
||||
|
||||
SumSqrFunc func = getSumSqrFunc(depth);
|
||||
|
||||
@@ -550,20 +593,22 @@ void meanStdDev(InputArray _src, OutputArray _mean, OutputArray _sdv, InputArray
|
||||
sq[k] = std::sqrt(std::max(sq[k]*scale - s[k]*s[k], 0.));
|
||||
}
|
||||
|
||||
for( j = 0; j < 2; j++ )
|
||||
if (_mean.needed())
|
||||
{
|
||||
const double* sptr = j == 0 ? s : sq;
|
||||
_OutputArray _dst = j == 0 ? _mean : _sdv;
|
||||
if( !_dst.needed() )
|
||||
continue;
|
||||
const double* sptr = s;
|
||||
int dcn = (int)mean_mat.total();
|
||||
double* dptr = mean_mat.ptr<double>();
|
||||
for( k = 0; k < cn; k++ )
|
||||
dptr[k] = sptr[k];
|
||||
for( ; k < dcn; k++ )
|
||||
dptr[k] = 0;
|
||||
}
|
||||
|
||||
if( !_dst.fixedSize() )
|
||||
_dst.create(cn, 1, CV_64F, -1, true);
|
||||
Mat dst = _dst.getMat();
|
||||
int dcn = (int)dst.total();
|
||||
CV_Assert( dst.type() == CV_64F && dst.isContinuous() &&
|
||||
(dst.cols == 1 || dst.rows == 1) && dcn >= cn );
|
||||
double* dptr = dst.ptr<double>();
|
||||
if (_sdv.needed())
|
||||
{
|
||||
const double* sptr = sq;
|
||||
int dcn = (int)stddev_mat.total();
|
||||
double* dptr = stddev_mat.ptr<double>();
|
||||
for( k = 0; k < cn; k++ )
|
||||
dptr[k] = sptr[k];
|
||||
for( ; k < dcn; k++ )
|
||||
|
||||
@@ -309,6 +309,33 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
|
||||
ocl_minMaxIdx(_src, minVal, maxVal, minIdx, maxIdx, _mask))
|
||||
|
||||
Mat src = _src.getMat(), mask = _mask.getMat();
|
||||
|
||||
if (src.dims <= 2)
|
||||
{
|
||||
CALL_HAL(minMaxIdx, cv_hal_minMaxIdx, src.data, src.step, src.cols*cn, src.rows,
|
||||
src.depth(), minVal, maxVal, minIdx, maxIdx, mask.data);
|
||||
}
|
||||
else if (src.isContinuous())
|
||||
{
|
||||
int res = cv_hal_minMaxIdx(src.data, 0, (int)src.total()*cn, 1, src.depth(),
|
||||
minVal, maxVal, minIdx, maxIdx, mask.data);
|
||||
|
||||
if (res == CV_HAL_ERROR_OK)
|
||||
{
|
||||
// minIdx[0] and minIdx[0] are always 0 for "flatten" version
|
||||
if (minIdx)
|
||||
ofs2idx(src, minIdx[1], minIdx);
|
||||
if (maxIdx)
|
||||
ofs2idx(src, maxIdx[1], maxIdx);
|
||||
return;
|
||||
}
|
||||
else if (res != CV_HAL_ERROR_NOT_IMPLEMENTED)
|
||||
{
|
||||
CV_Error_(cv::Error::StsInternal,
|
||||
("HAL implementation minMaxIdx ==> " CVAUX_STR(cv_hal_minMaxIdx) " returned %d (0x%08x)", res, res));
|
||||
}
|
||||
}
|
||||
|
||||
MinMaxIdxFunc func = getMinMaxIdxFunc(depth);
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
|
||||
@@ -52,6 +52,9 @@ static const uchar popCountTable4[] =
|
||||
|
||||
int normHamming(const uchar* a, int n, int cellSize)
|
||||
{
|
||||
int output;
|
||||
CALL_HAL_RET(normHamming8u, cv_hal_normHamming8u, output, a, n, cellSize);
|
||||
|
||||
if( cellSize == 1 )
|
||||
return normHamming(a, n);
|
||||
const uchar* tab = 0;
|
||||
@@ -98,6 +101,9 @@ int normHamming(const uchar* a, int n, int cellSize)
|
||||
|
||||
int normHamming(const uchar* a, const uchar* b, int n, int cellSize)
|
||||
{
|
||||
int output;
|
||||
CALL_HAL_RET(normHammingDiff8u, cv_hal_normHammingDiff8u, output, a, b, n, cellSize);
|
||||
|
||||
if( cellSize == 1 )
|
||||
return normHamming(a, b, n);
|
||||
const uchar* tab = 0;
|
||||
|
||||
@@ -271,7 +271,7 @@ randf_64f( double* arr, int len_, int cn, uint64* state, const Vec2d* p, void*,
|
||||
typedef void (*RandFunc)(uchar* arr, int len, int cn, uint64* state,
|
||||
const void* p, void* tempbuf, int flags);
|
||||
|
||||
static RandFunc randTab[][CV_DEPTH_MAX] =
|
||||
static RandFunc randTab[CV_DEPTH_MAX][CV_DEPTH_MAX] =
|
||||
{
|
||||
{
|
||||
(RandFunc)randi_8u, (RandFunc)randi_8s, (RandFunc)randi_16u,
|
||||
|
||||
Reference in New Issue
Block a user