Skip to content

Commit 9620cb5

Browse files
committed
Calls to OpenVX HAL disabled for images less than FullHD
1 parent fd93ae0 commit 9620cb5

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

3rdparty/openvx/hal/openvx_hal.cpp

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ inline bool dimTooBig(int size)
8181
return false;
8282
}
8383

84+
inline bool skipSmallImages(int w, int h, int kernel_id)
85+
{
86+
//OpenVX calls have essential overhead so it make sense to skip them for small images
87+
if (w*h < 1920 * 1080)
88+
return true;
89+
else
90+
return false;
91+
}
92+
8493
inline void setConstantBorder(ivx::border_t &border, vx_uint8 val)
8594
{
8695
border.mode = VX_BORDER_CONSTANT;
@@ -122,10 +131,12 @@ class vxImage: public ivx::Image
122131
// real code starts here
123132
// ...
124133

125-
#define OVX_BINARY_OP(hal_func, ovx_call) \
134+
#define OVX_BINARY_OP(hal_func, ovx_call, kernel_id) \
126135
template <typename T> \
127136
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) \
128137
{ \
138+
if(skipSmallImages(w, h, kernel_id)) \
139+
return CV_HAL_ERROR_NOT_IMPLEMENTED; \
129140
if(dimTooBig(w) || dimTooBig(h)) \
130141
return CV_HAL_ERROR_NOT_IMPLEMENTED; \
131142
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,
156167
return CV_HAL_ERROR_OK; \
157168
}
158169

159-
OVX_BINARY_OP(add, { ivx::IVX_CHECK_STATUS(vxuAdd(ctx, ia, ib, VX_CONVERT_POLICY_SATURATE, ic)); })
160-
OVX_BINARY_OP(sub, { ivx::IVX_CHECK_STATUS(vxuSubtract(ctx, ia, ib, VX_CONVERT_POLICY_SATURATE, ic)); })
170+
OVX_BINARY_OP(add, { ivx::IVX_CHECK_STATUS(vxuAdd(ctx, ia, ib, VX_CONVERT_POLICY_SATURATE, ic)); }, VX_KERNEL_ADD)
171+
OVX_BINARY_OP(sub, { ivx::IVX_CHECK_STATUS(vxuSubtract(ctx, ia, ib, VX_CONVERT_POLICY_SATURATE, ic)); }, VX_KERNEL_SUBTRACT)
161172

162-
OVX_BINARY_OP(absdiff, { ivx::IVX_CHECK_STATUS(vxuAbsDiff(ctx, ia, ib, ic)); })
173+
OVX_BINARY_OP(absdiff, { ivx::IVX_CHECK_STATUS(vxuAbsDiff(ctx, ia, ib, ic)); }, VX_KERNEL_ABSDIFF)
163174

164-
OVX_BINARY_OP(and, { ivx::IVX_CHECK_STATUS(vxuAnd(ctx, ia, ib, ic)); })
165-
OVX_BINARY_OP(or , { ivx::IVX_CHECK_STATUS(vxuOr(ctx, ia, ib, ic)); })
166-
OVX_BINARY_OP(xor, { ivx::IVX_CHECK_STATUS(vxuXor(ctx, ia, ib, ic)); })
175+
OVX_BINARY_OP(and, { ivx::IVX_CHECK_STATUS(vxuAnd(ctx, ia, ib, ic)); }, VX_KERNEL_AND)
176+
OVX_BINARY_OP(or , { ivx::IVX_CHECK_STATUS(vxuOr(ctx, ia, ib, ic)); }, VX_KERNEL_OR)
177+
OVX_BINARY_OP(xor, { ivx::IVX_CHECK_STATUS(vxuXor(ctx, ia, ib, ic)); }, VX_KERNEL_XOR)
167178

168179
template <typename T>
169180
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)
170181
{
182+
if(skipSmallImages(w, h, VX_KERNEL_MULTIPLY))
183+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
171184
if (dimTooBig(w) || dimTooBig(h))
172185
return CV_HAL_ERROR_NOT_IMPLEMENTED;
173186
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
234247

235248
int ovx_hal_not(const uchar *a, size_t astep, uchar *c, size_t cstep, int w, int h)
236249
{
250+
if (skipSmallImages(w, h, VX_KERNEL_NOT))
251+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
237252
if (dimTooBig(w) || dimTooBig(h))
238253
return CV_HAL_ERROR_NOT_IMPLEMENTED;
239254
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
263278

264279
int ovx_hal_merge8u(const uchar **src_data, uchar *dst_data, int len, int cn)
265280
{
281+
if (skipSmallImages(len, 1, VX_KERNEL_CHANNEL_COMBINE))
282+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
266283
if (dimTooBig(len))
267284
return CV_HAL_ERROR_NOT_IMPLEMENTED;
268285
if (cn != 3 && cn != 4)
@@ -299,6 +316,8 @@ int ovx_hal_merge8u(const uchar **src_data, uchar *dst_data, int len, int cn)
299316

300317
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)
301318
{
319+
if (skipSmallImages(aw, ah, VX_KERNEL_SCALE_IMAGE))
320+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
302321
if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
303322
return CV_HAL_ERROR_NOT_IMPLEMENTED;
304323
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
350369

351370
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])
352371
{
372+
if (skipSmallImages(aw, ah, VX_KERNEL_WARP_AFFINE))
373+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
353374
if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
354375
return CV_HAL_ERROR_NOT_IMPLEMENTED;
355376
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,
410431

411432
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])
412433
{
434+
if (skipSmallImages(aw, ah, VX_KERNEL_WARP_PERSPECTIVE))
435+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
413436
if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
414437
return CV_HAL_ERROR_NOT_IMPLEMENTED;
415438
refineStep(aw, ah, VX_DF_IMAGE_U8, astep);
@@ -558,6 +581,8 @@ int ovx_hal_filterFree(cvhalFilter2D *filter_context)
558581

559582
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)
560583
{
584+
if (skipSmallImages(w, h, VX_KERNEL_CUSTOM_CONVOLUTION))
585+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
561586
if (dimTooBig(w) || dimTooBig(h))
562587
return CV_HAL_ERROR_NOT_IMPLEMENTED;
563588
try
@@ -782,6 +807,8 @@ int ovx_hal_morphFree(cvhalFilter2D *filter_context)
782807

783808
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)
784809
{
810+
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
811+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
785812
if (dimTooBig(w) || dimTooBig(h))
786813
return CV_HAL_ERROR_NOT_IMPLEMENTED;
787814
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 *
823850

824851
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)
825852
{
853+
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
854+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
826855
if (dimTooBig(w) || dimTooBig(h))
827856
return CV_HAL_ERROR_NOT_IMPLEMENTED;
828857
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,
857886

858887
int ovx_hal_cvtGraytoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int depth, int bcn)
859888
{
889+
if (skipSmallImages(w, h, VX_KERNEL_CHANNEL_COMBINE))
890+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
860891
if (dimTooBig(w) || dimTooBig(h))
861892
return CV_HAL_ERROR_NOT_IMPLEMENTED;
862893
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,
890921

891922
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)
892923
{
924+
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
925+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
893926
if (dimTooBig(w) || dimTooBig(h))
894927
return CV_HAL_ERROR_NOT_IMPLEMENTED;
895928
if (!swapBlue || (bcn != 3 && bcn != 4))
@@ -934,6 +967,8 @@ int ovx_hal_cvtTwoPlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t
934967

935968
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)
936969
{
970+
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
971+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
937972
if (dimTooBig(w) || dimTooBig(h))
938973
return CV_HAL_ERROR_NOT_IMPLEMENTED;
939974
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
9821017

9831018
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)
9841019
{
1020+
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
1021+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
9851022
if (dimTooBig(w) || dimTooBig(h))
9861023
return CV_HAL_ERROR_NOT_IMPLEMENTED;
9871024
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
10281065

10291066
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)
10301067
{
1068+
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
1069+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
10311070
if (dimTooBig(w) || dimTooBig(h))
10321071
return CV_HAL_ERROR_NOT_IMPLEMENTED;
10331072
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
10651104

10661105
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)
10671106
{
1107+
if (skipSmallImages(w, h, VX_KERNEL_INTEGRAL_IMAGE))
1108+
return CV_HAL_ERROR_NOT_IMPLEMENTED;
10681109
if (depth != CV_8U || sdepth != CV_32S || c != NULL || d != NULL || cn != 1)
10691110
return CV_HAL_ERROR_NOT_IMPLEMENTED;
10701111
refineStep(w, h, VX_DF_IMAGE_U8, astep);

0 commit comments

Comments
 (0)