Calls to OpenVX HAL disabled for images less than FullHD

This commit is contained in:
Vitaly Tuzov 2017-03-23 20:14:05 +03:00
parent fd93ae08b6
commit 9620cb550d

View File

@ -81,6 +81,15 @@ inline bool dimTooBig(int size)
return false; return false;
} }
inline bool skipSmallImages(int w, int h, int kernel_id)
{
//OpenVX calls have essential overhead so it make sense to skip them for small images
if (w*h < 1920 * 1080)
return true;
else
return false;
}
inline void setConstantBorder(ivx::border_t &border, vx_uint8 val) inline void setConstantBorder(ivx::border_t &border, vx_uint8 val)
{ {
border.mode = VX_BORDER_CONSTANT; border.mode = VX_BORDER_CONSTANT;
@ -122,10 +131,12 @@ public:
// real code starts here // real code starts here
// ... // ...
#define OVX_BINARY_OP(hal_func, ovx_call) \ #define OVX_BINARY_OP(hal_func, ovx_call, kernel_id) \
template <typename T> \ template <typename T> \
int ovx_hal_##hal_func(const T *a, size_t astep, const T *b, size_t bstep, T *c, size_t cstep, int w, int h) \ int ovx_hal_##hal_func(const T *a, size_t astep, const T *b, size_t bstep, T *c, size_t cstep, int w, int h) \
{ \ { \
if(skipSmallImages(w, h, kernel_id)) \
return CV_HAL_ERROR_NOT_IMPLEMENTED; \
if(dimTooBig(w) || dimTooBig(h)) \ if(dimTooBig(w) || dimTooBig(h)) \
return CV_HAL_ERROR_NOT_IMPLEMENTED; \ return CV_HAL_ERROR_NOT_IMPLEMENTED; \
refineStep(w, h, ivx::TypeToEnum<T>::imgType, astep); \ refineStep(w, h, ivx::TypeToEnum<T>::imgType, astep); \
@ -156,18 +167,20 @@ int ovx_hal_##hal_func(const T *a, size_t astep, const T *b, size_t bstep, T *c,
return CV_HAL_ERROR_OK; \ return CV_HAL_ERROR_OK; \
} }
OVX_BINARY_OP(add, { ivx::IVX_CHECK_STATUS(vxuAdd(ctx, ia, ib, VX_CONVERT_POLICY_SATURATE, ic)); }) OVX_BINARY_OP(add, { ivx::IVX_CHECK_STATUS(vxuAdd(ctx, ia, ib, VX_CONVERT_POLICY_SATURATE, ic)); }, VX_KERNEL_ADD)
OVX_BINARY_OP(sub, { ivx::IVX_CHECK_STATUS(vxuSubtract(ctx, ia, ib, VX_CONVERT_POLICY_SATURATE, ic)); }) OVX_BINARY_OP(sub, { ivx::IVX_CHECK_STATUS(vxuSubtract(ctx, ia, ib, VX_CONVERT_POLICY_SATURATE, ic)); }, VX_KERNEL_SUBTRACT)
OVX_BINARY_OP(absdiff, { ivx::IVX_CHECK_STATUS(vxuAbsDiff(ctx, ia, ib, ic)); }) OVX_BINARY_OP(absdiff, { ivx::IVX_CHECK_STATUS(vxuAbsDiff(ctx, ia, ib, ic)); }, VX_KERNEL_ABSDIFF)
OVX_BINARY_OP(and, { ivx::IVX_CHECK_STATUS(vxuAnd(ctx, ia, ib, ic)); }) OVX_BINARY_OP(and, { ivx::IVX_CHECK_STATUS(vxuAnd(ctx, ia, ib, ic)); }, VX_KERNEL_AND)
OVX_BINARY_OP(or , { ivx::IVX_CHECK_STATUS(vxuOr(ctx, ia, ib, ic)); }) OVX_BINARY_OP(or , { ivx::IVX_CHECK_STATUS(vxuOr(ctx, ia, ib, ic)); }, VX_KERNEL_OR)
OVX_BINARY_OP(xor, { ivx::IVX_CHECK_STATUS(vxuXor(ctx, ia, ib, ic)); }) OVX_BINARY_OP(xor, { ivx::IVX_CHECK_STATUS(vxuXor(ctx, ia, ib, ic)); }, VX_KERNEL_XOR)
template <typename T> template <typename T>
int ovx_hal_mul(const T *a, size_t astep, const T *b, size_t bstep, T *c, size_t cstep, int w, int h, double scale) int ovx_hal_mul(const T *a, size_t astep, const T *b, size_t bstep, T *c, size_t cstep, int w, int h, double scale)
{ {
if(skipSmallImages(w, h, VX_KERNEL_MULTIPLY))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(w) || dimTooBig(h)) if (dimTooBig(w) || dimTooBig(h))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
refineStep(w, h, ivx::TypeToEnum<T>::imgType, astep); refineStep(w, h, ivx::TypeToEnum<T>::imgType, astep);
@ -234,6 +247,8 @@ template int ovx_hal_mul<short>(const short *a, size_t astep, const short *b, si
int ovx_hal_not(const uchar *a, size_t astep, uchar *c, size_t cstep, int w, int h) int ovx_hal_not(const uchar *a, size_t astep, uchar *c, size_t cstep, int w, int h)
{ {
if (skipSmallImages(w, h, VX_KERNEL_NOT))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(w) || dimTooBig(h)) if (dimTooBig(w) || dimTooBig(h))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
refineStep(w, h, VX_DF_IMAGE_U8, astep); refineStep(w, h, VX_DF_IMAGE_U8, astep);
@ -263,6 +278,8 @@ int ovx_hal_not(const uchar *a, size_t astep, uchar *c, size_t cstep, int w, int
int ovx_hal_merge8u(const uchar **src_data, uchar *dst_data, int len, int cn) int ovx_hal_merge8u(const uchar **src_data, uchar *dst_data, int len, int cn)
{ {
if (skipSmallImages(len, 1, VX_KERNEL_CHANNEL_COMBINE))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(len)) if (dimTooBig(len))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (cn != 3 && cn != 4) if (cn != 3 && cn != 4)
@ -299,6 +316,8 @@ int ovx_hal_merge8u(const uchar **src_data, uchar *dst_data, int len, int cn)
int ovx_hal_resize(int atype, const uchar *a, size_t astep, int aw, int ah, uchar *b, size_t bstep, int bw, int bh, double inv_scale_x, double inv_scale_y, int interpolation) int ovx_hal_resize(int atype, const uchar *a, size_t astep, int aw, int ah, uchar *b, size_t bstep, int bw, int bh, double inv_scale_x, double inv_scale_y, int interpolation)
{ {
if (skipSmallImages(aw, ah, VX_KERNEL_SCALE_IMAGE))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh)) if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
refineStep(aw, ah, VX_DF_IMAGE_U8, astep); refineStep(aw, ah, VX_DF_IMAGE_U8, astep);
@ -350,6 +369,8 @@ int ovx_hal_resize(int atype, const uchar *a, size_t astep, int aw, int ah, ucha
int ovx_hal_warpAffine(int atype, const uchar *a, size_t astep, int aw, int ah, uchar *b, size_t bstep, int bw, int bh, const double M[6], int interpolation, int borderType, const double borderValue[4]) int ovx_hal_warpAffine(int atype, const uchar *a, size_t astep, int aw, int ah, uchar *b, size_t bstep, int bw, int bh, const double M[6], int interpolation, int borderType, const double borderValue[4])
{ {
if (skipSmallImages(aw, ah, VX_KERNEL_WARP_AFFINE))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh)) if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
refineStep(aw, ah, VX_DF_IMAGE_U8, astep); refineStep(aw, ah, VX_DF_IMAGE_U8, astep);
@ -410,6 +431,8 @@ int ovx_hal_warpAffine(int atype, const uchar *a, size_t astep, int aw, int ah,
int ovx_hal_warpPerspectve(int atype, const uchar *a, size_t astep, int aw, int ah, uchar *b, size_t bstep, int bw, int bh, const double M[9], int interpolation, int borderType, const double borderValue[4]) int ovx_hal_warpPerspectve(int atype, const uchar *a, size_t astep, int aw, int ah, uchar *b, size_t bstep, int bw, int bh, const double M[9], int interpolation, int borderType, const double borderValue[4])
{ {
if (skipSmallImages(aw, ah, VX_KERNEL_WARP_PERSPECTIVE))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh)) if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
refineStep(aw, ah, VX_DF_IMAGE_U8, astep); refineStep(aw, ah, VX_DF_IMAGE_U8, astep);
@ -558,6 +581,8 @@ int ovx_hal_filterFree(cvhalFilter2D *filter_context)
int ovx_hal_filter(cvhalFilter2D *filter_context, uchar *a, size_t astep, uchar *b, size_t bstep, int w, int h, int, int, int, int) int ovx_hal_filter(cvhalFilter2D *filter_context, uchar *a, size_t astep, uchar *b, size_t bstep, int w, int h, int, int, int, int)
{ {
if (skipSmallImages(w, h, VX_KERNEL_CUSTOM_CONVOLUTION))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(w) || dimTooBig(h)) if (dimTooBig(w) || dimTooBig(h))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
try try
@ -782,6 +807,8 @@ int ovx_hal_morphFree(cvhalFilter2D *filter_context)
int ovx_hal_morph(cvhalFilter2D *filter_context, uchar *a, size_t astep, uchar *b, size_t bstep, int w, int h, int, int, int, int, int, int, int, int) int ovx_hal_morph(cvhalFilter2D *filter_context, uchar *a, size_t astep, uchar *b, size_t bstep, int w, int h, int, int, int, int, int, int, int, int)
{ {
if (skipSmallImages(w, h, VX_KERNEL_DILATE_3x3))//Actually it make sense to separate checks if implementations of dilation and erosion have different performance gain
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(w) || dimTooBig(h)) if (dimTooBig(w) || dimTooBig(h))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
refineStep(w, h, VX_DF_IMAGE_U8, astep); refineStep(w, h, VX_DF_IMAGE_U8, astep);
@ -823,6 +850,8 @@ int ovx_hal_morph(cvhalFilter2D *filter_context, uchar *a, size_t astep, uchar *
int ovx_hal_cvtBGRtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int depth, int acn, int bcn, bool swapBlue) int ovx_hal_cvtBGRtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int depth, int acn, int bcn, bool swapBlue)
{ {
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(w) || dimTooBig(h)) if (dimTooBig(w) || dimTooBig(h))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (depth != CV_8U || swapBlue || acn == bcn || (acn != 3 && acn != 4) || (bcn != 3 && bcn != 4)) if (depth != CV_8U || swapBlue || acn == bcn || (acn != 3 && acn != 4) || (bcn != 3 && bcn != 4))
@ -857,6 +886,8 @@ int ovx_hal_cvtBGRtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep,
int ovx_hal_cvtGraytoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int depth, int bcn) int ovx_hal_cvtGraytoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int depth, int bcn)
{ {
if (skipSmallImages(w, h, VX_KERNEL_CHANNEL_COMBINE))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(w) || dimTooBig(h)) if (dimTooBig(w) || dimTooBig(h))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (depth != CV_8U || (bcn != 3 && bcn != 4)) if (depth != CV_8U || (bcn != 3 && bcn != 4))
@ -890,6 +921,8 @@ int ovx_hal_cvtGraytoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep,
int ovx_hal_cvtTwoPlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int bcn, bool swapBlue, int uIdx) int ovx_hal_cvtTwoPlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int bcn, bool swapBlue, int uIdx)
{ {
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(w) || dimTooBig(h)) if (dimTooBig(w) || dimTooBig(h))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (!swapBlue || (bcn != 3 && bcn != 4)) if (!swapBlue || (bcn != 3 && bcn != 4))
@ -934,6 +967,8 @@ int ovx_hal_cvtTwoPlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t
int ovx_hal_cvtThreePlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int bcn, bool swapBlue, int uIdx) int ovx_hal_cvtThreePlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int bcn, bool swapBlue, int uIdx)
{ {
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(w) || dimTooBig(h)) if (dimTooBig(w) || dimTooBig(h))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (!swapBlue || (bcn != 3 && bcn != 4) || uIdx || (size_t)w / 2 != astep - (size_t)w / 2) if (!swapBlue || (bcn != 3 && bcn != 4) || uIdx || (size_t)w / 2 != astep - (size_t)w / 2)
@ -982,6 +1017,8 @@ int ovx_hal_cvtThreePlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size
int ovx_hal_cvtBGRtoThreePlaneYUV(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int acn, bool swapBlue, int uIdx) int ovx_hal_cvtBGRtoThreePlaneYUV(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int acn, bool swapBlue, int uIdx)
{ {
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(w) || dimTooBig(h)) if (dimTooBig(w) || dimTooBig(h))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (!swapBlue || (acn != 3 && acn != 4) || uIdx || (size_t)w / 2 != bstep - (size_t)w / 2) if (!swapBlue || (acn != 3 && acn != 4) || uIdx || (size_t)w / 2 != bstep - (size_t)w / 2)
@ -1028,6 +1065,8 @@ int ovx_hal_cvtBGRtoThreePlaneYUV(const uchar * a, size_t astep, uchar * b, size
int ovx_hal_cvtOnePlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int bcn, bool swapBlue, int uIdx, int ycn) int ovx_hal_cvtOnePlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int bcn, bool swapBlue, int uIdx, int ycn)
{ {
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (dimTooBig(w) || dimTooBig(h)) if (dimTooBig(w) || dimTooBig(h))
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (!swapBlue || (bcn != 3 && bcn != 4) || uIdx) if (!swapBlue || (bcn != 3 && bcn != 4) || uIdx)
@ -1065,6 +1104,8 @@ int ovx_hal_cvtOnePlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t
int ovx_hal_integral(int depth, int sdepth, int, const uchar * a, size_t astep, uchar * b, size_t bstep, uchar * c, size_t, uchar * d, size_t, int w, int h, int cn) int ovx_hal_integral(int depth, int sdepth, int, const uchar * a, size_t astep, uchar * b, size_t bstep, uchar * c, size_t, uchar * d, size_t, int w, int h, int cn)
{ {
if (skipSmallImages(w, h, VX_KERNEL_INTEGRAL_IMAGE))
return CV_HAL_ERROR_NOT_IMPLEMENTED;
if (depth != CV_8U || sdepth != CV_32S || c != NULL || d != NULL || cn != 1) if (depth != CV_8U || sdepth != CV_32S || c != NULL || d != NULL || cn != 1)
return CV_HAL_ERROR_NOT_IMPLEMENTED; return CV_HAL_ERROR_NOT_IMPLEMENTED;
refineStep(w, h, VX_DF_IMAGE_U8, astep); refineStep(w, h, VX_DF_IMAGE_U8, astep);