Skip to content

Commit bf5b784

Browse files
committed
Extended set of OpenVX HAL calls disabled for small images
1 parent 62fab57 commit bf5b784

File tree

15 files changed

+89
-50
lines changed

15 files changed

+89
-50
lines changed

3rdparty/openvx/hal/openvx_hal.cpp

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,10 @@ inline bool dimTooBig(int size)
8181
return false;
8282
}
8383

84-
inline bool skipSmallImages(int w, int h, int kernel_id)
85-
{
8684
//OpenVX calls have essential overhead so it make sense to skip them for small images
87-
switch (kernel_id)
88-
{
89-
case VX_KERNEL_MULTIPLY:
90-
if (w*h < 640 * 480)
91-
return true;
92-
break;
93-
case VX_KERNEL_COLOR_CONVERT:
94-
if (w*h < 2048 * 1536)
95-
return true;
96-
break;
97-
default:
98-
if (w*h < 3840 * 2160)
99-
return true;
100-
break;
101-
}
102-
return false;
103-
}
85+
template <int kernel_id> inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; }
86+
template <> inline bool skipSmallImages<VX_KERNEL_MULTIPLY>(int w, int h) { return w*h < 640 * 480; }
87+
template <> inline bool skipSmallImages<VX_KERNEL_COLOR_CONVERT>(int w, int h) { return w*h < 2048 * 1536; }
10488

10589
inline void setConstantBorder(ivx::border_t &border, vx_uint8 val)
10690
{
@@ -147,7 +131,7 @@ class vxImage: public ivx::Image
147131
template <typename T> \
148132
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) \
149133
{ \
150-
if(skipSmallImages(w, h, kernel_id)) \
134+
if(skipSmallImages<kernel_id>(w, h)) \
151135
return CV_HAL_ERROR_NOT_IMPLEMENTED; \
152136
if(dimTooBig(w) || dimTooBig(h)) \
153137
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
191175
template <typename T>
192176
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)
193177
{
194-
if(skipSmallImages(w, h, VX_KERNEL_MULTIPLY))
178+
if(skipSmallImages<VX_KERNEL_MULTIPLY>(w, h))
195179
return CV_HAL_ERROR_NOT_IMPLEMENTED;
196180
if (dimTooBig(w) || dimTooBig(h))
197181
return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -259,7 +243,7 @@ template int ovx_hal_mul<short>(const short *a, size_t astep, const short *b, si
259243

260244
int ovx_hal_not(const uchar *a, size_t astep, uchar *c, size_t cstep, int w, int h)
261245
{
262-
if (skipSmallImages(w, h, VX_KERNEL_NOT))
246+
if (skipSmallImages<VX_KERNEL_NOT>(w, h))
263247
return CV_HAL_ERROR_NOT_IMPLEMENTED;
264248
if (dimTooBig(w) || dimTooBig(h))
265249
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
290274

291275
int ovx_hal_merge8u(const uchar **src_data, uchar *dst_data, int len, int cn)
292276
{
293-
if (skipSmallImages(len, 1, VX_KERNEL_CHANNEL_COMBINE))
277+
if (skipSmallImages<VX_KERNEL_CHANNEL_COMBINE>(len, 1))
294278
return CV_HAL_ERROR_NOT_IMPLEMENTED;
295279
if (dimTooBig(len))
296280
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)
328312

329313
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)
330314
{
331-
if (skipSmallImages(aw, ah, VX_KERNEL_SCALE_IMAGE))
315+
if (skipSmallImages<VX_KERNEL_SCALE_IMAGE>(aw, ah))
332316
return CV_HAL_ERROR_NOT_IMPLEMENTED;
333317
if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
334318
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
381365

382366
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])
383367
{
384-
if (skipSmallImages(aw, ah, VX_KERNEL_WARP_AFFINE))
368+
if (skipSmallImages<VX_KERNEL_WARP_AFFINE>(aw, ah))
385369
return CV_HAL_ERROR_NOT_IMPLEMENTED;
386370
if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
387371
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,
443427

444428
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])
445429
{
446-
if (skipSmallImages(aw, ah, VX_KERNEL_WARP_PERSPECTIVE))
430+
if (skipSmallImages<VX_KERNEL_WARP_PERSPECTIVE>(aw, ah))
447431
return CV_HAL_ERROR_NOT_IMPLEMENTED;
448432
if (dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
449433
return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -593,7 +577,7 @@ int ovx_hal_filterFree(cvhalFilter2D *filter_context)
593577

594578
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)
595579
{
596-
if (skipSmallImages(w, h, VX_KERNEL_CUSTOM_CONVOLUTION))
580+
if (skipSmallImages<VX_KERNEL_CUSTOM_CONVOLUTION>(w, h))
597581
return CV_HAL_ERROR_NOT_IMPLEMENTED;
598582
if (dimTooBig(w) || dimTooBig(h))
599583
return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -819,7 +803,7 @@ int ovx_hal_morphFree(cvhalFilter2D *filter_context)
819803

820804
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)
821805
{
822-
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
806+
if (skipSmallImages<VX_KERNEL_DILATE_3x3>(w, h))//Actually it make sense to separate checks if implementations of dilation and erosion have different performance gain
823807
return CV_HAL_ERROR_NOT_IMPLEMENTED;
824808
if (dimTooBig(w) || dimTooBig(h))
825809
return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -862,7 +846,7 @@ int ovx_hal_morph(cvhalFilter2D *filter_context, uchar *a, size_t astep, uchar *
862846

863847
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)
864848
{
865-
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
849+
if (skipSmallImages<VX_KERNEL_COLOR_CONVERT>(w, h))
866850
return CV_HAL_ERROR_NOT_IMPLEMENTED;
867851
if (dimTooBig(w) || dimTooBig(h))
868852
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,
898882

899883
int ovx_hal_cvtGraytoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int depth, int bcn)
900884
{
901-
if (skipSmallImages(w, h, VX_KERNEL_CHANNEL_COMBINE))
885+
if (skipSmallImages<VX_KERNEL_CHANNEL_COMBINE>(w, h))
902886
return CV_HAL_ERROR_NOT_IMPLEMENTED;
903887
if (dimTooBig(w) || dimTooBig(h))
904888
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,
933917

934918
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)
935919
{
936-
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
920+
if (skipSmallImages<VX_KERNEL_COLOR_CONVERT>(w, h))
937921
return CV_HAL_ERROR_NOT_IMPLEMENTED;
938922
if (dimTooBig(w) || dimTooBig(h))
939923
return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -979,7 +963,7 @@ int ovx_hal_cvtTwoPlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t
979963

980964
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)
981965
{
982-
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
966+
if (skipSmallImages<VX_KERNEL_COLOR_CONVERT>(w, h))
983967
return CV_HAL_ERROR_NOT_IMPLEMENTED;
984968
if (dimTooBig(w) || dimTooBig(h))
985969
return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -1029,7 +1013,7 @@ int ovx_hal_cvtThreePlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size
10291013

10301014
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)
10311015
{
1032-
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
1016+
if (skipSmallImages<VX_KERNEL_COLOR_CONVERT>(w, h))
10331017
return CV_HAL_ERROR_NOT_IMPLEMENTED;
10341018
if (dimTooBig(w) || dimTooBig(h))
10351019
return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -1077,7 +1061,7 @@ int ovx_hal_cvtBGRtoThreePlaneYUV(const uchar * a, size_t astep, uchar * b, size
10771061

10781062
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)
10791063
{
1080-
if (skipSmallImages(w, h, VX_KERNEL_COLOR_CONVERT))
1064+
if (skipSmallImages<VX_KERNEL_COLOR_CONVERT>(w, h))
10811065
return CV_HAL_ERROR_NOT_IMPLEMENTED;
10821066
if (dimTooBig(w) || dimTooBig(h))
10831067
return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -1116,7 +1100,7 @@ int ovx_hal_cvtOnePlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t
11161100

11171101
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)
11181102
{
1119-
if (skipSmallImages(w, h, VX_KERNEL_INTEGRAL_IMAGE))
1103+
if (skipSmallImages<VX_KERNEL_INTEGRAL_IMAGE>(w, h))
11201104
return CV_HAL_ERROR_NOT_IMPLEMENTED;
11211105
if (depth != CV_8U || sdepth != CV_32S || c != NULL || d != NULL || cn != 1)
11221106
return CV_HAL_ERROR_NOT_IMPLEMENTED;

modules/core/include/opencv2/core/openvx/ovx_defs.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ namespace cv{
2424
namespace ovx{
2525
// Get common thread local OpenVX context
2626
CV_EXPORTS_W ivx::Context& getOpenVXContext();
27+
28+
template <int kernel_id> inline bool skipSmallImages(int w, int h) { return w*h < 3840 * 2160; }
29+
template <> inline bool skipSmallImages<VX_KERNEL_MINMAXLOC>(int w, int h) { return w*h < 1280*720; }
30+
template <> inline bool skipSmallImages<VX_KERNEL_MEDIAN_3x3>(int w, int h) { return w*h < 1280 * 720; }
31+
template <> inline bool skipSmallImages<VX_KERNEL_GAUSSIAN_3x3>(int w, int h) { return w*h < 1280 * 720; }
32+
template <> inline bool skipSmallImages<VX_KERNEL_BOX_3x3>(int w, int h) { return w*h < 1280 * 720; }
33+
template <> inline bool skipSmallImages<VX_KERNEL_HISTOGRAM>(int w, int h) { return w*h < 2048 * 1536; }
34+
template <> inline bool skipSmallImages<VX_KERNEL_SOBEL_3x3>(int w, int h) { return w*h < 640 * 480; }
35+
template <> inline bool skipSmallImages<VX_KERNEL_CUSTOM_CONVOLUTION>(int w, int h) { return w*h < 1280 * 720; }
36+
2737
}}
2838

2939
#define CV_OVX_RUN(condition, func, ...) \

modules/core/src/convert.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4671,6 +4671,9 @@ static bool _openvx_cvt(const T* src, size_t sstep,
46714671

46724672
int srcType = DataType<T>::type, dstType = DataType<DT>::type;
46734673

4674+
if (ovx::skipSmallImages<VX_KERNEL_CONVERTDEPTH>(imgSize.width, imgSize.height))
4675+
return false;
4676+
46744677
try
46754678
{
46764679
Context context = ovx::getOpenVXContext();
@@ -5696,7 +5699,7 @@ void cv::LUT( InputArray _src, InputArray _lut, OutputArray _dst )
56965699
_dst.create(src.dims, src.size, CV_MAKETYPE(_lut.depth(), cn));
56975700
Mat dst = _dst.getMat();
56985701

5699-
CV_OVX_RUN(true,
5702+
CV_OVX_RUN(!ovx::skipSmallImages<VX_KERNEL_TABLE_LOOKUP>(src.cols, src.rows),
57005703
openvx_LUT(src, dst, lut))
57015704

57025705
CV_IPP_RUN(_src.dims() <= 2, ipp_lut(src, lut, dst));

modules/core/src/stat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input
18431843
Mat src = _src.getMat(), mask = _mask.getMat();
18441844
CV_Assert( mask.empty() || mask.type() == CV_8UC1 );
18451845

1846-
CV_OVX_RUN(true,
1846+
CV_OVX_RUN(!ovx::skipSmallImages<VX_KERNEL_MEAN_STDDEV>(src.cols, src.rows),
18471847
openvx_meanStdDev(src, _mean, _sdv, mask))
18481848

18491849
CV_IPP_RUN(IPP_VERSION_X100 >= 700, ipp_meanStdDev(src, _mean, _sdv, mask));
@@ -2496,7 +2496,7 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
24962496

24972497
Mat src = _src.getMat(), mask = _mask.getMat();
24982498

2499-
CV_OVX_RUN(true,
2499+
CV_OVX_RUN(!ovx::skipSmallImages<VX_KERNEL_MINMAXLOC>(src.cols, src.rows),
25002500
openvx_minMaxIdx(src, minVal, maxVal, minIdx, maxIdx, mask))
25012501

25022502
CV_IPP_RUN(IPP_VERSION_X100 >= 700, ipp_minMaxIdx(src, minVal, maxVal, minIdx, maxIdx, mask))

modules/features2d/src/fast.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ static bool openvx_FAST(InputArray _img, std::vector<KeyPoint>& keypoints,
352352
if(imgMat.empty() || imgMat.type() != CV_8UC1)
353353
return false;
354354

355+
if (ovx::skipSmallImages<VX_KERNEL_FAST_CORNERS>(imgMat.cols, imgMat.rows))
356+
return false;
357+
355358
try
356359
{
357360
Context context = ovx::getOpenVXContext();

modules/imgproc/src/accum.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,8 @@ enum
19451945
static bool openvx_accumulate(InputArray _src, InputOutputArray _dst, InputArray _mask, double _weight, int opType)
19461946
{
19471947
Mat srcMat = _src.getMat(), dstMat = _dst.getMat();
1948+
if (ovx::skipSmallImages<VX_KERNEL_ACCUMULATE>(srcMat.cols, srcMat.rows))
1949+
return false;
19481950
if(!_mask.empty() ||
19491951
(opType == VX_ACCUMULATE_WEIGHTED_OP && dstMat.type() != CV_8UC1 ) ||
19501952
(opType != VX_ACCUMULATE_WEIGHTED_OP && dstMat.type() != CV_16SC1 ) ||

modules/imgproc/src/canny.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,8 @@ void Canny( InputArray _src, OutputArray _dst,
868868
src.type() == CV_8UC1 &&
869869
!src.isSubmatrix() &&
870870
src.cols >= aperture_size &&
871-
src.rows >= aperture_size,
871+
src.rows >= aperture_size &&
872+
!ovx::skipSmallImages<VX_KERNEL_CANNY_EDGE_DETECTOR>(src.cols, src.rows),
872873
openvx_canny(
873874
src,
874875
dst,

modules/imgproc/src/deriv.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ namespace cv
191191
int stype = _src.type();
192192
int dtype = _dst.type();
193193
if (stype != CV_8UC1 || (dtype != CV_16SC1 && dtype != CV_8UC1) ||
194-
ksize < 3 || ksize % 2 != 1 || delta != 0.0)
194+
ksize != 3 || delta != 0.0)//Restrict to 3x3 kernels since otherwise convolution would be slower than separable filter
195195
return false;
196196

197197
Mat src = _src.getMat();
@@ -200,6 +200,12 @@ namespace cv
200200
if (src.cols < ksize || src.rows < ksize)
201201
return false;
202202

203+
if (dtype == CV_16SC1 && ksize == 3 && ((dx | dy) == 1) && (dx + dy) == 1 ?
204+
ovx::skipSmallImages<VX_KERNEL_SOBEL_3x3>(src.cols, src.rows) :
205+
ovx::skipSmallImages<VX_KERNEL_CUSTOM_CONVOLUTION>(src.cols, src.rows)
206+
)
207+
return false;
208+
203209
int iscale = 1;
204210
vx_uint32 cscale = 1;
205211
if(scale != 1.0)
@@ -237,8 +243,8 @@ namespace cv
237243
try
238244
{
239245
ivx::Context ctx = ovx::getOpenVXContext();
240-
if ((vx_size)ksize > ctx.convolutionMaxDimension())
241-
return false;
246+
//if ((vx_size)ksize > ctx.convolutionMaxDimension())
247+
// return false;
242248

243249
Mat a;
244250
if (dst.data != src.data)

modules/imgproc/src/featureselect.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
377377
}
378378

379379
// Disabled due to bad accuracy
380-
CV_OVX_RUN(false && useHarrisDetector && _mask.empty(),
380+
CV_OVX_RUN(false && useHarrisDetector && _mask.empty() &&
381+
!ovx::skipSmallImages<VX_KERNEL_HARRIS_CORNERS>(image.cols, image.rows),
381382
openvx_harris(image, _corners, maxCorners, qualityLevel, minDistance, blockSize, harrisK))
382383

383384
if( useHarrisDetector )

modules/imgproc/src/histogram.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,8 @@ void cv::calcHist( const Mat* images, int nimages, const int* channels,
13761376
images && histSize &&
13771377
nimages == 1 && images[0].type() == CV_8UC1 && dims == 1 && _mask.getMat().empty() &&
13781378
(!channels || channels[0] == 0) && !accumulate && uniform &&
1379-
ranges && ranges[0],
1379+
ranges && ranges[0] &&
1380+
!ovx::skipSmallImages<VX_KERNEL_HISTOGRAM>(images[0].cols, images[0].rows),
13801381
openvx_calchist(images[0], _hist, histSize[0], ranges[0]))
13811382

13821383
CV_IPP_RUN(nimages == 1 && images[0].type() == CV_8UC1 && dims == 1 && channels &&
@@ -3817,7 +3818,7 @@ void cv::equalizeHist( InputArray _src, OutputArray _dst )
38173818
_dst.create( src.size(), src.type() );
38183819
Mat dst = _dst.getMat();
38193820

3820-
CV_OVX_RUN(true,
3821+
CV_OVX_RUN(!ovx::skipSmallImages<VX_KERNEL_EQUALIZE_HISTOGRAM>(src.cols, src.rows),
38213822
openvx_equalize_hist(src, dst))
38223823

38233824
Mutex histogramLockInstance;

0 commit comments

Comments
 (0)