From 9620cb550d561c1433089db91cc853854a3319ca Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Thu, 23 Mar 2017 20:14:05 +0300 Subject: [PATCH 1/9] Calls to OpenVX HAL disabled for images less than FullHD --- 3rdparty/openvx/hal/openvx_hal.cpp | 55 ++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/3rdparty/openvx/hal/openvx_hal.cpp b/3rdparty/openvx/hal/openvx_hal.cpp index df2d6788ef..add86c0bde 100644 --- a/3rdparty/openvx/hal/openvx_hal.cpp +++ b/3rdparty/openvx/hal/openvx_hal.cpp @@ -81,6 +81,15 @@ inline bool dimTooBig(int size) 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) { border.mode = VX_BORDER_CONSTANT; @@ -122,10 +131,12 @@ public: // real code starts here // ... -#define OVX_BINARY_OP(hal_func, ovx_call) \ +#define OVX_BINARY_OP(hal_func, ovx_call, kernel_id) \ template \ 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)) \ return CV_HAL_ERROR_NOT_IMPLEMENTED; \ refineStep(w, h, ivx::TypeToEnum::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; \ } -OVX_BINARY_OP(add, { ivx::IVX_CHECK_STATUS(vxuAdd(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)); }) +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)); }, 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(or , { ivx::IVX_CHECK_STATUS(vxuOr(ctx, ia, ib, ic)); }) -OVX_BINARY_OP(xor, { ivx::IVX_CHECK_STATUS(vxuXor(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)); }, VX_KERNEL_OR) +OVX_BINARY_OP(xor, { ivx::IVX_CHECK_STATUS(vxuXor(ctx, ia, ib, ic)); }, VX_KERNEL_XOR) template 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)) return CV_HAL_ERROR_NOT_IMPLEMENTED; refineStep(w, h, ivx::TypeToEnum::imgType, astep); @@ -234,6 +247,8 @@ template int ovx_hal_mul(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) { + if (skipSmallImages(w, h, VX_KERNEL_NOT)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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) { + if (skipSmallImages(len, 1, VX_KERNEL_CHANNEL_COMBINE)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(len)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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) { + if (skipSmallImages(aw, ah, VX_KERNEL_SCALE_IMAGE)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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]) { + if (skipSmallImages(aw, ah, VX_KERNEL_WARP_AFFINE)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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]) { + if (skipSmallImages(aw, ah, VX_KERNEL_WARP_PERSPECTIVE)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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) { + if (skipSmallImages(w, h, VX_KERNEL_CUSTOM_CONVOLUTION)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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) { + 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)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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) { + if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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) { + if (skipSmallImages(w, h, VX_KERNEL_CHANNEL_COMBINE)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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) { + if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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) { + if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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) { + if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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) { + if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT)) + return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; 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) { + 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) return CV_HAL_ERROR_NOT_IMPLEMENTED; refineStep(w, h, VX_DF_IMAGE_U8, astep); From 62fab57c3e3e8fb4c6b13a2a9f3e1381a0eb3ee0 Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Fri, 24 Mar 2017 16:08:56 +0300 Subject: [PATCH 2/9] Tune OpenVX HAL usability checks to distinguish multiplication and color conversion kernels --- 3rdparty/openvx/hal/openvx_hal.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/3rdparty/openvx/hal/openvx_hal.cpp b/3rdparty/openvx/hal/openvx_hal.cpp index add86c0bde..14889b4ec8 100644 --- a/3rdparty/openvx/hal/openvx_hal.cpp +++ b/3rdparty/openvx/hal/openvx_hal.cpp @@ -84,10 +84,22 @@ inline bool dimTooBig(int size) 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; + switch (kernel_id) + { + case VX_KERNEL_MULTIPLY: + if (w*h < 640 * 480) + return true; + break; + case VX_KERNEL_COLOR_CONVERT: + if (w*h < 2048 * 1536) + return true; + break; + default: + if (w*h < 3840 * 2160) + return true; + break; + } + return false; } inline void setConstantBorder(ivx::border_t &border, vx_uint8 val) From bf5b7843e8fdb539d7663e2c2b371f2e28fd71fe Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Tue, 28 Mar 2017 18:02:42 +0300 Subject: [PATCH 3/9] Extended set of OpenVX HAL calls disabled for small images --- 3rdparty/openvx/hal/openvx_hal.cpp | 54 +++++++------------ .../include/opencv2/core/openvx/ovx_defs.hpp | 10 ++++ modules/core/src/convert.cpp | 5 +- modules/core/src/stat.cpp | 4 +- modules/features2d/src/fast.cpp | 3 ++ modules/imgproc/src/accum.cpp | 2 + modules/imgproc/src/canny.cpp | 3 +- modules/imgproc/src/deriv.cpp | 12 +++-- modules/imgproc/src/featureselect.cpp | 3 +- modules/imgproc/src/histogram.cpp | 5 +- modules/imgproc/src/imgwarp.cpp | 1 + modules/imgproc/src/pyramids.cpp | 3 ++ modules/imgproc/src/smooth.cpp | 29 ++++++++-- modules/imgproc/src/thresh.cpp | 2 +- modules/video/src/lkpyramid.cpp | 3 ++ 15 files changed, 89 insertions(+), 50 deletions(-) diff --git a/3rdparty/openvx/hal/openvx_hal.cpp b/3rdparty/openvx/hal/openvx_hal.cpp index 14889b4ec8..b6ff4ed3b2 100644 --- a/3rdparty/openvx/hal/openvx_hal.cpp +++ b/3rdparty/openvx/hal/openvx_hal.cpp @@ -81,26 +81,10 @@ inline bool dimTooBig(int size) 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 - switch (kernel_id) - { - case VX_KERNEL_MULTIPLY: - if (w*h < 640 * 480) - return true; - break; - case VX_KERNEL_COLOR_CONVERT: - if (w*h < 2048 * 1536) - return true; - break; - default: - if (w*h < 3840 * 2160) - return true; - break; - } - return false; -} +template inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } inline void setConstantBorder(ivx::border_t &border, vx_uint8 val) { @@ -147,7 +131,7 @@ public: template \ 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)) \ + if(skipSmallImages(w, h)) \ return CV_HAL_ERROR_NOT_IMPLEMENTED; \ if(dimTooBig(w) || dimTooBig(h)) \ return CV_HAL_ERROR_NOT_IMPLEMENTED; \ @@ -191,7 +175,7 @@ OVX_BINARY_OP(xor, { ivx::IVX_CHECK_STATUS(vxuXor(ctx, ia, ib, ic)); }, VX_KERNE template 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)) + if(skipSmallImages(w, h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -259,7 +243,7 @@ template int ovx_hal_mul(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) { - if (skipSmallImages(w, h, VX_KERNEL_NOT)) + if (skipSmallImages(w, h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -290,7 +274,7 @@ 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) { - if (skipSmallImages(len, 1, VX_KERNEL_CHANNEL_COMBINE)) + if (skipSmallImages(len, 1)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(len)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -328,7 +312,7 @@ 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) { - if (skipSmallImages(aw, ah, VX_KERNEL_SCALE_IMAGE)) + if (skipSmallImages(aw, ah)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -381,7 +365,7 @@ 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]) { - if (skipSmallImages(aw, ah, VX_KERNEL_WARP_AFFINE)) + if (skipSmallImages(aw, ah)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -443,7 +427,7 @@ 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]) { - if (skipSmallImages(aw, ah, VX_KERNEL_WARP_PERSPECTIVE)) + if (skipSmallImages(aw, ah)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -593,7 +577,7 @@ 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) { - if (skipSmallImages(w, h, VX_KERNEL_CUSTOM_CONVOLUTION)) + if (skipSmallImages(w, h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -819,7 +803,7 @@ 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) { - 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 + if (skipSmallImages(w, h))//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)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -862,7 +846,7 @@ 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) { - if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT)) + if (skipSmallImages(w, h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -898,7 +882,7 @@ 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) { - if (skipSmallImages(w, h, VX_KERNEL_CHANNEL_COMBINE)) + if (skipSmallImages(w, h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -933,7 +917,7 @@ 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) { - if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT)) + if (skipSmallImages(w, h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -979,7 +963,7 @@ 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) { - if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT)) + if (skipSmallImages(w, h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -1029,7 +1013,7 @@ 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) { - if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT)) + if (skipSmallImages(w, h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -1077,7 +1061,7 @@ 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) { - if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT)) + if (skipSmallImages(w, h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -1116,7 +1100,7 @@ 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) { - if (skipSmallImages(w, h, VX_KERNEL_INTEGRAL_IMAGE)) + if (skipSmallImages(w, h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (depth != CV_8U || sdepth != CV_32S || c != NULL || d != NULL || cn != 1) return CV_HAL_ERROR_NOT_IMPLEMENTED; diff --git a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp index 19964c4c47..9c23a83df3 100644 --- a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp +++ b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp @@ -24,6 +24,16 @@ namespace cv{ namespace ovx{ // Get common thread local OpenVX context CV_EXPORTS_W ivx::Context& getOpenVXContext(); + +template inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280*720; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } + }} #define CV_OVX_RUN(condition, func, ...) \ diff --git a/modules/core/src/convert.cpp b/modules/core/src/convert.cpp index 6c060f9c9c..d1c31f7bb7 100644 --- a/modules/core/src/convert.cpp +++ b/modules/core/src/convert.cpp @@ -4671,6 +4671,9 @@ static bool _openvx_cvt(const T* src, size_t sstep, int srcType = DataType::type, dstType = DataType
::type; + if (ovx::skipSmallImages(imgSize.width, imgSize.height)) + return false; + try { Context context = ovx::getOpenVXContext(); @@ -5696,7 +5699,7 @@ void cv::LUT( InputArray _src, InputArray _lut, OutputArray _dst ) _dst.create(src.dims, src.size, CV_MAKETYPE(_lut.depth(), cn)); Mat dst = _dst.getMat(); - CV_OVX_RUN(true, + CV_OVX_RUN(!ovx::skipSmallImages(src.cols, src.rows), openvx_LUT(src, dst, lut)) CV_IPP_RUN(_src.dims() <= 2, ipp_lut(src, lut, dst)); diff --git a/modules/core/src/stat.cpp b/modules/core/src/stat.cpp index 3c5fb73de4..3bf753bbeb 100644 --- a/modules/core/src/stat.cpp +++ b/modules/core/src/stat.cpp @@ -1843,7 +1843,7 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input Mat src = _src.getMat(), mask = _mask.getMat(); CV_Assert( mask.empty() || mask.type() == CV_8UC1 ); - CV_OVX_RUN(true, + CV_OVX_RUN(!ovx::skipSmallImages(src.cols, src.rows), openvx_meanStdDev(src, _mean, _sdv, mask)) CV_IPP_RUN(IPP_VERSION_X100 >= 700, ipp_meanStdDev(src, _mean, _sdv, mask)); @@ -2496,7 +2496,7 @@ void cv::minMaxIdx(InputArray _src, double* minVal, Mat src = _src.getMat(), mask = _mask.getMat(); - CV_OVX_RUN(true, + CV_OVX_RUN(!ovx::skipSmallImages(src.cols, src.rows), openvx_minMaxIdx(src, minVal, maxVal, minIdx, maxIdx, mask)) CV_IPP_RUN(IPP_VERSION_X100 >= 700, ipp_minMaxIdx(src, minVal, maxVal, minIdx, maxIdx, mask)) diff --git a/modules/features2d/src/fast.cpp b/modules/features2d/src/fast.cpp index 8aad5b0433..551be5af0f 100644 --- a/modules/features2d/src/fast.cpp +++ b/modules/features2d/src/fast.cpp @@ -352,6 +352,9 @@ static bool openvx_FAST(InputArray _img, std::vector& keypoints, if(imgMat.empty() || imgMat.type() != CV_8UC1) return false; + if (ovx::skipSmallImages(imgMat.cols, imgMat.rows)) + return false; + try { Context context = ovx::getOpenVXContext(); diff --git a/modules/imgproc/src/accum.cpp b/modules/imgproc/src/accum.cpp index 34a7e07c39..771a82c101 100644 --- a/modules/imgproc/src/accum.cpp +++ b/modules/imgproc/src/accum.cpp @@ -1945,6 +1945,8 @@ enum static bool openvx_accumulate(InputArray _src, InputOutputArray _dst, InputArray _mask, double _weight, int opType) { Mat srcMat = _src.getMat(), dstMat = _dst.getMat(); + if (ovx::skipSmallImages(srcMat.cols, srcMat.rows)) + return false; if(!_mask.empty() || (opType == VX_ACCUMULATE_WEIGHTED_OP && dstMat.type() != CV_8UC1 ) || (opType != VX_ACCUMULATE_WEIGHTED_OP && dstMat.type() != CV_16SC1 ) || diff --git a/modules/imgproc/src/canny.cpp b/modules/imgproc/src/canny.cpp index d10b5f7dfa..214d4e9c0c 100644 --- a/modules/imgproc/src/canny.cpp +++ b/modules/imgproc/src/canny.cpp @@ -868,7 +868,8 @@ void Canny( InputArray _src, OutputArray _dst, src.type() == CV_8UC1 && !src.isSubmatrix() && src.cols >= aperture_size && - src.rows >= aperture_size, + src.rows >= aperture_size && + !ovx::skipSmallImages(src.cols, src.rows), openvx_canny( src, dst, diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index 8486ec899b..8d2a987361 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -191,7 +191,7 @@ namespace cv int stype = _src.type(); int dtype = _dst.type(); if (stype != CV_8UC1 || (dtype != CV_16SC1 && dtype != CV_8UC1) || - ksize < 3 || ksize % 2 != 1 || delta != 0.0) + ksize != 3 || delta != 0.0)//Restrict to 3x3 kernels since otherwise convolution would be slower than separable filter return false; Mat src = _src.getMat(); @@ -200,6 +200,12 @@ namespace cv if (src.cols < ksize || src.rows < ksize) return false; + if (dtype == CV_16SC1 && ksize == 3 && ((dx | dy) == 1) && (dx + dy) == 1 ? + ovx::skipSmallImages(src.cols, src.rows) : + ovx::skipSmallImages(src.cols, src.rows) + ) + return false; + int iscale = 1; vx_uint32 cscale = 1; if(scale != 1.0) @@ -237,8 +243,8 @@ namespace cv try { ivx::Context ctx = ovx::getOpenVXContext(); - if ((vx_size)ksize > ctx.convolutionMaxDimension()) - return false; + //if ((vx_size)ksize > ctx.convolutionMaxDimension()) + // return false; Mat a; if (dst.data != src.data) diff --git a/modules/imgproc/src/featureselect.cpp b/modules/imgproc/src/featureselect.cpp index ee94153900..8bdd5175d0 100644 --- a/modules/imgproc/src/featureselect.cpp +++ b/modules/imgproc/src/featureselect.cpp @@ -377,7 +377,8 @@ void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners, } // Disabled due to bad accuracy - CV_OVX_RUN(false && useHarrisDetector && _mask.empty(), + CV_OVX_RUN(false && useHarrisDetector && _mask.empty() && + !ovx::skipSmallImages(image.cols, image.rows), openvx_harris(image, _corners, maxCorners, qualityLevel, minDistance, blockSize, harrisK)) if( useHarrisDetector ) diff --git a/modules/imgproc/src/histogram.cpp b/modules/imgproc/src/histogram.cpp index a0a2909511..cd86da48f2 100644 --- a/modules/imgproc/src/histogram.cpp +++ b/modules/imgproc/src/histogram.cpp @@ -1376,7 +1376,8 @@ void cv::calcHist( const Mat* images, int nimages, const int* channels, images && histSize && nimages == 1 && images[0].type() == CV_8UC1 && dims == 1 && _mask.getMat().empty() && (!channels || channels[0] == 0) && !accumulate && uniform && - ranges && ranges[0], + ranges && ranges[0] && + !ovx::skipSmallImages(images[0].cols, images[0].rows), openvx_calchist(images[0], _hist, histSize[0], ranges[0])) CV_IPP_RUN(nimages == 1 && images[0].type() == CV_8UC1 && dims == 1 && channels && @@ -3817,7 +3818,7 @@ void cv::equalizeHist( InputArray _src, OutputArray _dst ) _dst.create( src.size(), src.type() ); Mat dst = _dst.getMat(); - CV_OVX_RUN(true, + CV_OVX_RUN(!ovx::skipSmallImages(src.cols, src.rows), openvx_equalize_hist(src, dst)) Mutex histogramLockInstance; diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index 84a7e5218a..5ccadd2a77 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -4935,6 +4935,7 @@ void cv::remap( InputArray _src, OutputArray _dst, CV_OVX_RUN( src.type() == CV_8UC1 && dst.type() == CV_8UC1 && + !ovx::skipSmallImages(src.cols, src.rows) && (borderType& ~BORDER_ISOLATED) == BORDER_CONSTANT && ((map1.type() == CV_32FC2 && map2.empty() && map1.size == dst.size) || (map1.type() == CV_32FC1 && map2.type() == CV_32FC1 && map1.size == dst.size && map2.size == dst.size) || diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index ff260d1783..357dd92f80 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -1265,6 +1265,9 @@ static bool openvx_pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, Mat srcMat = _src.getMat(); + if (ovx::skipSmallImages(srcMat.cols, srcMat.rows)) + return false; + CV_Assert(!srcMat.empty()); Size ssize = _src.size(); diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index d9c88d6dad..2574deba80 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1649,11 +1649,17 @@ namespace cv if (stype != CV_8UC1 || (ddepth != CV_8U && ddepth != CV_16S) || (anchor.x >= 0 && anchor.x != ksize.width / 2) || (anchor.y >= 0 && anchor.y != ksize.height / 2) || - ksize.width % 2 != 1 || ksize.height % 2 != 1 || - ksize.width < 3 || ksize.height < 3) + ksize.width != 3 || ksize.height != 3) return false; Mat src = _src.getMat(); + + if (ddepth == CV_8U && ksize.width == 3 && ksize.height == 3 && normalize ? + ovx::skipSmallImages(src.cols, src.rows) : + ovx::skipSmallImages(src.cols, src.rows) + ) + return false; + _dst.create(src.size(), CV_MAKETYPE(ddepth, 1)); Mat dst = _dst.getMat(); @@ -1678,8 +1684,8 @@ namespace cv try { ivx::Context ctx = ovx::getOpenVXContext(); - if ((vx_size)(ksize.width) > ctx.convolutionMaxDimension() || (vx_size)(ksize.height) > ctx.convolutionMaxDimension()) - return false; + //if ((vx_size)(ksize.width) > ctx.convolutionMaxDimension() || (vx_size)(ksize.height) > ctx.convolutionMaxDimension()) + // return false; Mat a; if (dst.data != src.data) @@ -2210,6 +2216,7 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, if (stype != CV_8UC1 || ksize.width < 3 || ksize.height < 3 || + ksize.width > 5 || ksize.height > 5 || ksize.width % 2 != 1 || ksize.height % 2 != 1) return false; @@ -2219,6 +2226,12 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, Mat src = _src.getMat(); Mat dst = _dst.getMat(); + if (ksize.width == 3 && ksize.height == 3 && (sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) && (sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON) ? + ovx::skipSmallImages(src.cols, src.rows) : + ovx::skipSmallImages(src.cols, src.rows) + ) + return false; + if (src.cols < ksize.width || src.rows < ksize.height) return false; @@ -3359,6 +3372,14 @@ namespace cv Mat src = _src.getMat(); Mat dst = _dst.getMat(); + if ( +#ifdef VX_VERSION_1_1 + ksize != 3 ? ovx::skipSmallImages(src.cols, src.rows) : +#endif + ovx::skipSmallImages(src.cols, src.rows) + ) + return false; + try { ivx::Context ctx = ovx::getOpenVXContext(); diff --git a/modules/imgproc/src/thresh.cpp b/modules/imgproc/src/thresh.cpp index bd2b73c0bb..c3df9f3d15 100644 --- a/modules/imgproc/src/thresh.cpp +++ b/modules/imgproc/src/thresh.cpp @@ -1390,7 +1390,7 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m return thresh; } - CV_OVX_RUN(true, + CV_OVX_RUN(!ovx::skipSmallImages(src.cols, src.rows), openvx_threshold(src, dst, ithresh, imaxval, type), (double)ithresh) thresh = ithresh; diff --git a/modules/video/src/lkpyramid.cpp b/modules/video/src/lkpyramid.cpp index 739bb10780..0c4e3bfeba 100644 --- a/modules/video/src/lkpyramid.cpp +++ b/modules/video/src/lkpyramid.cpp @@ -1074,6 +1074,9 @@ namespace if(prevImgMat.type() != CV_8UC1 || nextImgMat.type() != CV_8UC1) return false; + if (ovx::skipSmallImages(prevImgMat.cols, prevImgMat.rows)) + return false; + CV_Assert(prevImgMat.size() == nextImgMat.size()); Mat prevPtsMat = _prevPts.getMat(); int checkPrev = prevPtsMat.checkVector(2, CV_32F, false); From bf62dca45aef943a6791e2a990bfd567d85808f1 Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Wed, 29 Mar 2017 09:01:40 +0300 Subject: [PATCH 4/9] Extended restrictions for OpenVX HAL calls on small images --- 3rdparty/openvx/hal/openvx_hal.cpp | 6 ++++-- modules/core/include/opencv2/core/openvx/ovx_defs.hpp | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/3rdparty/openvx/hal/openvx_hal.cpp b/3rdparty/openvx/hal/openvx_hal.cpp index b6ff4ed3b2..8327fc55b2 100644 --- a/3rdparty/openvx/hal/openvx_hal.cpp +++ b/3rdparty/openvx/hal/openvx_hal.cpp @@ -82,7 +82,7 @@ inline bool dimTooBig(int size) } //OpenVX calls have essential overhead so it make sense to skip them for small images -template inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; } +template inline bool skipSmallImages(int w, int h) { return w*h < 7680 * 4320; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } @@ -175,7 +175,9 @@ OVX_BINARY_OP(xor, { ivx::IVX_CHECK_STATUS(vxuXor(ctx, ia, ib, ic)); }, VX_KERNE template 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)) + if(scale == 1.0 || sizeof(T) > 1 ? + skipSmallImages(w, h) : /*actually it could be any kernel with generic minimum size*/ + skipSmallImages(w, h) ) return CV_HAL_ERROR_NOT_IMPLEMENTED; if (dimTooBig(w) || dimTooBig(h)) return CV_HAL_ERROR_NOT_IMPLEMENTED; diff --git a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp index 9c23a83df3..09f3faa9f4 100644 --- a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp +++ b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp @@ -26,12 +26,12 @@ namespace ovx{ CV_EXPORTS_W ivx::Context& getOpenVXContext(); template inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280*720; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 1920 * 1080; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } }} From 0f1a56da7cbc611bb701dab97335f9471ac8e416 Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Wed, 29 Mar 2017 09:01:40 +0300 Subject: [PATCH 5/9] Changed restrictions for OpenVX HAL calls on small images --- 3rdparty/openvx/hal/openvx_hal.cpp | 7 ++++--- modules/core/include/opencv2/core/openvx/ovx_defs.hpp | 8 ++++---- modules/imgproc/src/deriv.cpp | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/3rdparty/openvx/hal/openvx_hal.cpp b/3rdparty/openvx/hal/openvx_hal.cpp index 8327fc55b2..2352809f97 100644 --- a/3rdparty/openvx/hal/openvx_hal.cpp +++ b/3rdparty/openvx/hal/openvx_hal.cpp @@ -82,9 +82,10 @@ inline bool dimTooBig(int size) } //OpenVX calls have essential overhead so it make sense to skip them for small images -template inline bool skipSmallImages(int w, int h) { return w*h < 7680 * 4320; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } +template inline bool skipSmallImages(int w, int h) { return w*h < 7680 * 4320; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } inline void setConstantBorder(ivx::border_t &border, vx_uint8 val) { diff --git a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp index 09f3faa9f4..c9212b3cce 100644 --- a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp +++ b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp @@ -28,11 +28,11 @@ CV_EXPORTS_W ivx::Context& getOpenVXContext(); template inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 1920 * 1080; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 320 * 240; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 320 * 240; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } }} diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index 8d2a987361..6328dfcdfc 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -234,8 +234,8 @@ namespace cv border = VX_BORDER_CONSTANT; break; case BORDER_REPLICATE: - border = VX_BORDER_REPLICATE; - break; +// border = VX_BORDER_REPLICATE; +// break; default: return false; } From 87bb74312b3c0908c896daf5e318e4981b2530b7 Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Tue, 11 Apr 2017 13:22:38 +0300 Subject: [PATCH 6/9] Disabled vxuConvolution call for Sobel, GaussianBlur and Box filter evaluation --- .../include/opencv2/core/openvx/ovx_defs.hpp | 1 - modules/imgproc/src/deriv.cpp | 71 +++----------- modules/imgproc/src/smooth.cpp | 98 ++++--------------- 3 files changed, 31 insertions(+), 139 deletions(-) diff --git a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp index c9212b3cce..c0d23a8921 100644 --- a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp +++ b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp @@ -32,7 +32,6 @@ template <> inline bool skipSmallImages(int w, int h) { template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 320 * 240; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } }} diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index 6328dfcdfc..d1f96f70dc 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -188,43 +188,17 @@ namespace cv int dx, int dy, int ksize, double scale, double delta, int borderType) { - int stype = _src.type(); - int dtype = _dst.type(); - if (stype != CV_8UC1 || (dtype != CV_16SC1 && dtype != CV_8UC1) || - ksize != 3 || delta != 0.0)//Restrict to 3x3 kernels since otherwise convolution would be slower than separable filter + if (_src.type() != CV_8UC1 || _dst.type() != CV_16SC1 || + ksize != 3 || scale != 1.0 || delta != 0.0 || + (dx | dy) != 1 || (dx + dy) != 1 || + _src.cols < ksize || _src.rows < ksize || + ovx::skipSmallImages(_src.cols, _src.rows) + ) return false; Mat src = _src.getMat(); Mat dst = _dst.getMat(); - if (src.cols < ksize || src.rows < ksize) - return false; - - if (dtype == CV_16SC1 && ksize == 3 && ((dx | dy) == 1) && (dx + dy) == 1 ? - ovx::skipSmallImages(src.cols, src.rows) : - ovx::skipSmallImages(src.cols, src.rows) - ) - return false; - - int iscale = 1; - vx_uint32 cscale = 1; - if(scale != 1.0) - { - iscale = static_cast(scale); - if (std::abs(scale - iscale) >= DBL_EPSILON) - { - int exp = 0; - float significand = frexp(scale, &exp); - if ((significand == 0.5f) && (exp <= 0)) - { - iscale = 1; - cscale = 1 << (exp = -exp + 1); - } - else - return false; - } - } - if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix()) return false; //Process isolated borders only vx_enum border; @@ -255,40 +229,17 @@ namespace cv ivx::Image ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8, ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data), - ib = ivx::Image::createFromHandle(ctx, dtype == CV_16SC1 ? VX_DF_IMAGE_S16 : VX_DF_IMAGE_U8, - ivx::Image::createAddressing(dst.cols, dst.rows, dtype == CV_16SC1 ? 2 : 1, (vx_int32)(dst.step)), dst.data); + ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_S16, + ivx::Image::createAddressing(dst.cols, dst.rows, 2, (vx_int32)(dst.step)), dst.data); //ATTENTION: VX_CONTEXT_IMMEDIATE_BORDER attribute change could lead to strange issues in multi-threaded environments //since OpenVX standart says nothing about thread-safety for now ivx::border_t prevBorder = ctx.immediateBorder(); ctx.setImmediateBorder(border, (vx_uint8)(0)); - if (dtype == CV_16SC1 && ksize == 3 && ((dx | dy) == 1) && (dx + dy) == 1) - { - if(dx) - ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, ib, NULL)); - else - ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, NULL, ib)); - } + if(dx) + ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, ib, NULL)); else - { -#if VX_VERSION <= VX_VERSION_1_0 - if (ctx.vendorID() == VX_ID_KHRONOS && ((vx_size)(src.cols) <= ctx.convolutionMaxDimension() || (vx_size)(src.rows) <= ctx.convolutionMaxDimension())) - { - ctx.setImmediateBorder(prevBorder); - return false; - } -#endif - Mat kx, ky; - getDerivKernels(kx, ky, dx, dy, ksize, false); - flip(kx, kx, 0); - flip(ky, ky, 0); - Mat convData; - cv::Mat(ky*kx.t()).convertTo(convData, CV_16SC1, iscale); - ivx::Convolution cnv = ivx::Convolution::create(ctx, convData.cols, convData.rows); - cnv.copyFrom(convData); - cnv.setScale(cscale); - ivx::IVX_CHECK_STATUS(vxuConvolve(ctx, ia, cnv, ib)); - } + ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, NULL, ib)); ctx.setImmediateBorder(prevBorder); } catch (ivx::RuntimeError & e) diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 2574deba80..7d6c7e21f3 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1643,29 +1643,18 @@ namespace cv Size ksize, Point anchor, bool normalize, int borderType) { - int stype = _src.type(); if (ddepth < 0) ddepth = CV_8UC1; - if (stype != CV_8UC1 || (ddepth != CV_8U && ddepth != CV_16S) || - (anchor.x >= 0 && anchor.x != ksize.width / 2) || - (anchor.y >= 0 && anchor.y != ksize.height / 2) || - ksize.width != 3 || ksize.height != 3) + if (_src.type() != CV_8UC1 || ddepth != CV_8U || !normalize || + _src.cols < 3 || _src.rows < 3 || + ksize.width != 3 || ksize.height != 3 || + (anchor.x >= 0 && anchor.x != 1) || + (anchor.y >= 0 && anchor.y != 1) || + ovx::skipSmallImages(_src.cols, _src.rows)) return false; Mat src = _src.getMat(); - if (ddepth == CV_8U && ksize.width == 3 && ksize.height == 3 && normalize ? - ovx::skipSmallImages(src.cols, src.rows) : - ovx::skipSmallImages(src.cols, src.rows) - ) - return false; - - _dst.create(src.size(), CV_MAKETYPE(ddepth, 1)); - Mat dst = _dst.getMat(); - - if (src.cols < ksize.width || src.rows < ksize.height) - return false; - if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix()) return false; //Process isolated borders only vx_enum border; @@ -1681,11 +1670,12 @@ namespace cv return false; } + _dst.create(src.size(), CV_8UC1); + Mat dst = _dst.getMat(); + try { ivx::Context ctx = ovx::getOpenVXContext(); - //if ((vx_size)(ksize.width) > ctx.convolutionMaxDimension() || (vx_size)(ksize.height) > ctx.convolutionMaxDimension()) - // return false; Mat a; if (dst.data != src.data) @@ -1696,34 +1686,14 @@ namespace cv ivx::Image ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8, ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data), - ib = ivx::Image::createFromHandle(ctx, ddepth == CV_16S ? VX_DF_IMAGE_S16 : VX_DF_IMAGE_U8, - ivx::Image::createAddressing(dst.cols, dst.rows, ddepth == CV_16S ? 2 : 1, (vx_int32)(dst.step)), dst.data); + ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8, + ivx::Image::createAddressing(dst.cols, dst.rows, 1, (vx_int32)(dst.step)), dst.data); //ATTENTION: VX_CONTEXT_IMMEDIATE_BORDER attribute change could lead to strange issues in multi-threaded environments //since OpenVX standart says nothing about thread-safety for now ivx::border_t prevBorder = ctx.immediateBorder(); ctx.setImmediateBorder(border, (vx_uint8)(0)); - if (ddepth == CV_8U && ksize.width == 3 && ksize.height == 3 && normalize) - { - ivx::IVX_CHECK_STATUS(vxuBox3x3(ctx, ia, ib)); - } - else - { -#if VX_VERSION <= VX_VERSION_1_0 - if (ctx.vendorID() == VX_ID_KHRONOS && ((vx_size)(src.cols) <= ctx.convolutionMaxDimension() || (vx_size)(src.rows) <= ctx.convolutionMaxDimension())) - { - ctx.setImmediateBorder(prevBorder); - return false; - } -#endif - Mat convData(ksize, CV_16SC1); - convData = normalize ? (1 << 15) / (ksize.width * ksize.height) : 1; - ivx::Convolution cnv = ivx::Convolution::create(ctx, convData.cols, convData.rows); - cnv.copyFrom(convData); - if (normalize) - cnv.setScale(1 << 15); - ivx::IVX_CHECK_STATUS(vxuConvolve(ctx, ia, cnv, ib)); - } + ivx::IVX_CHECK_STATUS(vxuBox3x3(ctx, ia, ib)); ctx.setImmediateBorder(prevBorder); } catch (ivx::RuntimeError & e) @@ -2205,7 +2175,6 @@ static bool ocl_GaussianBlur_8UC1(InputArray _src, OutputArray _dst, Size ksize, static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, double sigma1, double sigma2, int borderType) { - int stype = _src.type(); if (sigma2 <= 0) sigma2 = sigma1; // automatic detection of kernel size from sigma @@ -2214,27 +2183,21 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, if (ksize.height <= 0 && sigma2 > 0) ksize.height = cvRound(sigma2*6 + 1) | 1; - if (stype != CV_8UC1 || - ksize.width < 3 || ksize.height < 3 || - ksize.width > 5 || ksize.height > 5 || - ksize.width % 2 != 1 || ksize.height % 2 != 1) + if (_src.type() != CV_8UC1 || + _src.cols < 3 || _src.rows < 3 || + ksize.width != 3 || ksize.height != 3) return false; sigma1 = std::max(sigma1, 0.); sigma2 = std::max(sigma2, 0.); + if (!(sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) || !(sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON) || + ovx::skipSmallImages(_src.cols, _src.rows)) + return false; + Mat src = _src.getMat(); Mat dst = _dst.getMat(); - if (ksize.width == 3 && ksize.height == 3 && (sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) && (sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON) ? - ovx::skipSmallImages(src.cols, src.rows) : - ovx::skipSmallImages(src.cols, src.rows) - ) - return false; - - if (src.cols < ksize.width || src.rows < ksize.height) - return false; - if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix()) return false; //Process isolated borders only vx_enum border; @@ -2253,8 +2216,6 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, try { ivx::Context ctx = ovx::getOpenVXContext(); - if ((vx_size)(ksize.width) > ctx.convolutionMaxDimension() || (vx_size)(ksize.height) > ctx.convolutionMaxDimension()) - return false; Mat a; if (dst.data != src.data) @@ -2272,26 +2233,7 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, //since OpenVX standart says nothing about thread-safety for now ivx::border_t prevBorder = ctx.immediateBorder(); ctx.setImmediateBorder(border, (vx_uint8)(0)); - if (ksize.width == 3 && ksize.height == 3 && (sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) && (sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON)) - { - ivx::IVX_CHECK_STATUS(vxuGaussian3x3(ctx, ia, ib)); - } - else - { -#if VX_VERSION <= VX_VERSION_1_0 - if (ctx.vendorID() == VX_ID_KHRONOS && ((vx_size)(a.cols) <= ctx.convolutionMaxDimension() || (vx_size)(a.rows) <= ctx.convolutionMaxDimension())) - { - ctx.setImmediateBorder(prevBorder); - return false; - } -#endif - Mat convData; - cv::Mat(cv::getGaussianKernel(ksize.height, sigma2)*cv::getGaussianKernel(ksize.width, sigma1).t()).convertTo(convData, CV_16SC1, (1 << 15)); - ivx::Convolution cnv = ivx::Convolution::create(ctx, convData.cols, convData.rows); - cnv.copyFrom(convData); - cnv.setScale(1 << 15); - ivx::IVX_CHECK_STATUS(vxuConvolve(ctx, ia, cnv, ib)); - } + ivx::IVX_CHECK_STATUS(vxuGaussian3x3(ctx, ia, ib)); ctx.setImmediateBorder(prevBorder); } catch (ivx::RuntimeError & e) From 4c0d833dec63e2d4449a876ccd9fe4fac8d3f717 Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Tue, 11 Apr 2017 14:15:26 +0300 Subject: [PATCH 7/9] Disabled vxuConvolution call for sepFilter evaluation --- 3rdparty/openvx/hal/openvx_hal.hpp | 12 ++++++------ modules/imgproc/src/deriv.cpp | 4 ++-- modules/imgproc/src/smooth.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/3rdparty/openvx/hal/openvx_hal.hpp b/3rdparty/openvx/hal/openvx_hal.hpp index 93ea7b3f66..c94cde3158 100644 --- a/3rdparty/openvx/hal/openvx_hal.hpp +++ b/3rdparty/openvx/hal/openvx_hal.hpp @@ -106,12 +106,12 @@ int ovx_hal_integral(int depth, int sdepth, int, const uchar * a, size_t astep, #undef cv_hal_filterFree #define cv_hal_filterFree ovx_hal_filterFree -#undef cv_hal_sepFilterInit -#define cv_hal_sepFilterInit ovx_hal_sepFilterInit -#undef cv_hal_sepFilter -#define cv_hal_sepFilter ovx_hal_filter -#undef cv_hal_sepFilterFree -#define cv_hal_sepFilterFree ovx_hal_filterFree +//#undef cv_hal_sepFilterInit +//#define cv_hal_sepFilterInit ovx_hal_sepFilterInit +//#undef cv_hal_sepFilter +//#define cv_hal_sepFilter ovx_hal_filter +//#undef cv_hal_sepFilterFree +//#define cv_hal_sepFilterFree ovx_hal_filterFree #if VX_VERSION > VX_VERSION_1_0 diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index d1f96f70dc..bcea1b8b1f 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -191,8 +191,8 @@ namespace cv if (_src.type() != CV_8UC1 || _dst.type() != CV_16SC1 || ksize != 3 || scale != 1.0 || delta != 0.0 || (dx | dy) != 1 || (dx + dy) != 1 || - _src.cols < ksize || _src.rows < ksize || - ovx::skipSmallImages(_src.cols, _src.rows) + _src.cols() < ksize || _src.rows() < ksize || + ovx::skipSmallImages(_src.cols(), _src.rows()) ) return false; diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 7d6c7e21f3..2b695a4dc3 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1646,11 +1646,11 @@ namespace cv if (ddepth < 0) ddepth = CV_8UC1; if (_src.type() != CV_8UC1 || ddepth != CV_8U || !normalize || - _src.cols < 3 || _src.rows < 3 || + _src.cols() < 3 || _src.rows() < 3 || ksize.width != 3 || ksize.height != 3 || (anchor.x >= 0 && anchor.x != 1) || (anchor.y >= 0 && anchor.y != 1) || - ovx::skipSmallImages(_src.cols, _src.rows)) + ovx::skipSmallImages(_src.cols(), _src.rows())) return false; Mat src = _src.getMat(); @@ -2184,7 +2184,7 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, ksize.height = cvRound(sigma2*6 + 1) | 1; if (_src.type() != CV_8UC1 || - _src.cols < 3 || _src.rows < 3 || + _src.cols() < 3 || _src.rows() < 3 || ksize.width != 3 || ksize.height != 3) return false; @@ -2192,7 +2192,7 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, sigma2 = std::max(sigma2, 0.); if (!(sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) || !(sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON) || - ovx::skipSmallImages(_src.cols, _src.rows)) + ovx::skipSmallImages(_src.cols(), _src.rows())) return false; Mat src = _src.getMat(); From 9dc36a1ece1aeb55195ce825607ce256cb8c0f07 Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Fri, 14 Apr 2017 13:20:25 +0300 Subject: [PATCH 8/9] Tuned restrictions for Canny, Warp, FAST, Accumulate and Convolution OpenVX HAL calls on small images --- 3rdparty/openvx/hal/openvx_hal.cpp | 12 ++++++++---- .../core/include/opencv2/core/openvx/ovx_defs.hpp | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/3rdparty/openvx/hal/openvx_hal.cpp b/3rdparty/openvx/hal/openvx_hal.cpp index 2352809f97..562c1efbef 100644 --- a/3rdparty/openvx/hal/openvx_hal.cpp +++ b/3rdparty/openvx/hal/openvx_hal.cpp @@ -82,10 +82,13 @@ inline bool dimTooBig(int size) } //OpenVX calls have essential overhead so it make sense to skip them for small images -template inline bool skipSmallImages(int w, int h) { return w*h < 7680 * 4320; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } +template inline bool skipSmallImages(int w, int h) { return w*h < 7680 * 4320; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 320 * 240; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 320 * 240; } inline void setConstantBorder(ivx::border_t &border, vx_uint8 val) { @@ -553,6 +556,7 @@ int ovx_hal_filterInit(cvhalFilter2D **filter_context, uchar *kernel_data, size_ for (int i = 0; i < kernel_width; ++i) data.push_back(row[i]); } + break; default: return CV_HAL_ERROR_NOT_IMPLEMENTED; } diff --git a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp index c0d23a8921..089ccf8767 100644 --- a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp +++ b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp @@ -32,7 +32,9 @@ template <> inline bool skipSmallImages(int w, int h) { template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } template <> inline bool skipSmallImages(int w, int h) { return w*h < 320 * 240; } - +template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 120 * 60; } +template <> inline bool skipSmallImages(int w, int h) { return w*h < 800 * 600; } }} #define CV_OVX_RUN(condition, func, ...) \ From 1d62a025b3c3a43a274af20e7388f70858a06c00 Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Thu, 25 May 2017 19:10:21 +0300 Subject: [PATCH 9/9] Moved size restrictions for OpenVX processed images to corresponding cpp files --- modules/core/include/opencv2/core/openvx/ovx_defs.hpp | 9 --------- modules/core/src/stat.cpp | 3 +++ modules/features2d/src/fast.cpp | 3 +++ modules/imgproc/src/accum.cpp | 3 +++ modules/imgproc/src/canny.cpp | 3 +++ modules/imgproc/src/deriv.cpp | 3 +++ modules/imgproc/src/histogram.cpp | 3 +++ modules/imgproc/src/smooth.cpp | 9 +++++++++ 8 files changed, 27 insertions(+), 9 deletions(-) diff --git a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp index 089ccf8767..a29db1b8ff 100644 --- a/modules/core/include/opencv2/core/openvx/ovx_defs.hpp +++ b/modules/core/include/opencv2/core/openvx/ovx_defs.hpp @@ -26,15 +26,6 @@ namespace ovx{ CV_EXPORTS_W ivx::Context& getOpenVXContext(); template inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 320 * 240; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 320 * 240; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 120 * 60; } -template <> inline bool skipSmallImages(int w, int h) { return w*h < 800 * 600; } }} #define CV_OVX_RUN(condition, func, ...) \ diff --git a/modules/core/src/stat.cpp b/modules/core/src/stat.cpp index 3bf753bbeb..6559b5ce29 100644 --- a/modules/core/src/stat.cpp +++ b/modules/core/src/stat.cpp @@ -2300,6 +2300,9 @@ static bool ocl_minMaxIdx( InputArray _src, double* minVal, double* maxVal, int* #endif #ifdef HAVE_OPENVX +namespace ovx { + template <> inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; } +} static bool openvx_minMaxIdx(Mat &src, double* minVal, double* maxVal, int* minIdx, int* maxIdx, Mat &mask) { int stype = src.type(); diff --git a/modules/features2d/src/fast.cpp b/modules/features2d/src/fast.cpp index 551be5af0f..5b36023564 100644 --- a/modules/features2d/src/fast.cpp +++ b/modules/features2d/src/fast.cpp @@ -338,6 +338,9 @@ static bool ocl_FAST( InputArray _img, std::vector& keypoints, #ifdef HAVE_OPENVX +namespace ovx { + template <> inline bool skipSmallImages(int w, int h) { return w*h < 800 * 600; } +} static bool openvx_FAST(InputArray _img, std::vector& keypoints, int _threshold, bool nonmaxSuppression, int type) { diff --git a/modules/imgproc/src/accum.cpp b/modules/imgproc/src/accum.cpp index 771a82c101..941c100814 100644 --- a/modules/imgproc/src/accum.cpp +++ b/modules/imgproc/src/accum.cpp @@ -1942,6 +1942,9 @@ enum VX_ACCUMULATE_WEIGHTED_OP = 2 }; +namespace ovx { + template <> inline bool skipSmallImages(int w, int h) { return w*h < 120 * 60; } +} static bool openvx_accumulate(InputArray _src, InputOutputArray _dst, InputArray _mask, double _weight, int opType) { Mat srcMat = _src.getMat(), dstMat = _dst.getMat(); diff --git a/modules/imgproc/src/canny.cpp b/modules/imgproc/src/canny.cpp index 214d4e9c0c..fe38308127 100644 --- a/modules/imgproc/src/canny.cpp +++ b/modules/imgproc/src/canny.cpp @@ -778,6 +778,9 @@ private: }; #ifdef HAVE_OPENVX +namespace ovx { + template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } +} static bool openvx_canny(const Mat& src, Mat& dst, int loVal, int hiVal, int kSize, bool useL2) { using namespace ivx; diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index bcea1b8b1f..383ccf1a7f 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -184,6 +184,9 @@ cv::Ptr cv::createDerivFilter(int srcType, int dstType, #ifdef HAVE_OPENVX namespace cv { + namespace ovx { + template <> inline bool skipSmallImages(int w, int h) { return w*h < 320 * 240; } + } static bool openvx_sobel(InputArray _src, OutputArray _dst, int dx, int dy, int ksize, double scale, double delta, int borderType) diff --git a/modules/imgproc/src/histogram.cpp b/modules/imgproc/src/histogram.cpp index cd86da48f2..49aaf9b5a3 100644 --- a/modules/imgproc/src/histogram.cpp +++ b/modules/imgproc/src/histogram.cpp @@ -1267,6 +1267,9 @@ private: #ifdef HAVE_OPENVX namespace cv { + namespace ovx { + template <> inline bool skipSmallImages(int w, int h) { return w*h < 2048 * 1536; } + } static bool openvx_calchist(const Mat& image, OutputArray _hist, const int histSize, const float* _range) { diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 2b695a4dc3..f8867b78bc 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1639,6 +1639,9 @@ cv::Ptr cv::createBoxFilter( int srcType, int dstType, Size ks #ifdef HAVE_OPENVX namespace cv { + namespace ovx { + template <> inline bool skipSmallImages(int w, int h) { return w*h < 640 * 480; } + } static bool openvx_boxfilter(InputArray _src, OutputArray _dst, int ddepth, Size ksize, Point anchor, bool normalize, int borderType) @@ -2172,6 +2175,9 @@ static bool ocl_GaussianBlur_8UC1(InputArray _src, OutputArray _dst, Size ksize, #ifdef HAVE_OPENVX +namespace ovx { + template <> inline bool skipSmallImages(int w, int h) { return w*h < 320 * 240; } +} static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, double sigma1, double sigma2, int borderType) { @@ -3302,6 +3308,9 @@ static bool ocl_medianFilter(InputArray _src, OutputArray _dst, int m) #ifdef HAVE_OPENVX namespace cv { + namespace ovx { + template <> inline bool skipSmallImages(int w, int h) { return w*h < 1280 * 720; } + } static bool openvx_medianFilter(InputArray _src, OutputArray _dst, int ksize) { if (_src.type() != CV_8UC1 || _dst.type() != CV_8U