Skip to content

Commit 36b5abf

Browse files
committed
Merge pull request opencv#7857 from savuor:openvx_macro_wrappers
2 parents 059c2a8 + 8b9422a commit 36b5abf

File tree

9 files changed

+70
-143
lines changed

9 files changed

+70
-143
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@
3030
#define CV_OVX_RUN(condition, func, ...)
3131
#endif // HAVE_OPENVX
3232

33+
// Throw an error in debug mode or try another implementation in release
34+
#ifdef _DEBUG
35+
#define VX_DbgThrow(s) CV_Error(cv::Error::StsInternal, (s))
36+
#else
37+
#define VX_DbgThrow(s) return false
38+
#endif
39+
3340
#endif // OPENCV_OVX_DEFS_HPP

modules/core/src/convert.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4638,12 +4638,6 @@ cvtScaleHalf_<short, float>( const short* src, size_t sstep, float* dst, size_t
46384638

46394639
#ifdef HAVE_OPENVX
46404640

4641-
#ifdef _DEBUG
4642-
#define VX_DbgThrow(s) CV_Error(cv::Error::StsInternal, (s))
4643-
#else
4644-
#define VX_DbgThrow(s) return false;
4645-
#endif
4646-
46474641
template<typename T, typename DT>
46484642
static bool _openvx_cvt(const T* src, size_t sstep,
46494643
DT* dst, size_t dstep, Size continuousSize)
@@ -4734,7 +4728,7 @@ cvt_( const T* src, size_t sstep,
47344728
CV_OVX_RUN(
47354729
false,
47364730
openvx_cvt(src, sstep, dst, dstep, size)
4737-
);
4731+
)
47384732

47394733
sstep /= sizeof(src[0]);
47404734
dstep /= sizeof(dst[0]);
@@ -5407,13 +5401,11 @@ static bool openvx_LUT(Mat src, Mat dst, Mat _lut)
54075401
}
54085402
catch (ivx::RuntimeError & e)
54095403
{
5410-
CV_Error(CV_StsInternal, e.what());
5411-
return false;
5404+
VX_DbgThrow(e.what());
54125405
}
54135406
catch (ivx::WrapperError & e)
54145407
{
5415-
CV_Error(CV_StsInternal, e.what());
5416-
return false;
5408+
VX_DbgThrow(e.what());
54175409
}
54185410

54195411
return true;
@@ -5685,10 +5677,8 @@ void cv::LUT( InputArray _src, InputArray _lut, OutputArray _dst )
56855677
_dst.create(src.dims, src.size, CV_MAKETYPE(_lut.depth(), cn));
56865678
Mat dst = _dst.getMat();
56875679

5688-
#ifdef HAVE_OPENVX
5689-
if (openvx_LUT(src, dst, lut))
5690-
return;
5691-
#endif
5680+
CV_OVX_RUN(true,
5681+
openvx_LUT(src, dst, lut))
56925682

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

modules/core/src/stat.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@
4747

4848
#include "opencl_kernels_core.hpp"
4949

50-
#ifdef HAVE_OPENVX
51-
#define IVX_HIDE_INFO_WARNINGS
52-
#define IVX_USE_OPENCV
53-
#include "ivx.hpp"
54-
#endif
50+
#include "opencv2/core/openvx/ovx_defs.hpp"
5551

5652
namespace cv
5753
{
@@ -1706,19 +1702,17 @@ namespace cv
17061702
for (int c = 1; c < (int)stddev.total(); c++)
17071703
pstddev[c] = 0;
17081704
}
1709-
1710-
return true;
17111705
}
17121706
catch (ivx::RuntimeError & e)
17131707
{
1714-
CV_Error(CV_StsInternal, e.what());
1715-
return false;
1708+
VX_DbgThrow(e.what());
17161709
}
17171710
catch (ivx::WrapperError & e)
17181711
{
1719-
CV_Error(CV_StsInternal, e.what());
1720-
return false;
1712+
VX_DbgThrow(e.what());
17211713
}
1714+
1715+
return true;
17221716
}
17231717
}
17241718
#endif
@@ -1848,10 +1842,8 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input
18481842
Mat src = _src.getMat(), mask = _mask.getMat();
18491843
CV_Assert( mask.empty() || mask.type() == CV_8UC1 );
18501844

1851-
#ifdef HAVE_OPENVX
1852-
if (openvx_meanStdDev(src, _mean, _sdv, mask))
1853-
return;
1854-
#endif
1845+
CV_OVX_RUN(true,
1846+
openvx_meanStdDev(src, _mean, _sdv, mask))
18551847

18561848
CV_IPP_RUN(IPP_VERSION_X100 >= 700, ipp_meanStdDev(src, _mean, _sdv, mask));
18571849

@@ -2365,19 +2357,17 @@ static bool openvx_minMaxIdx(Mat &src, double* minVal, double* maxVal, int* minI
23652357
size_t maxidx = loc.y * cols + loc.x + 1;
23662358
ofs2idx(src, maxidx, maxIdx);
23672359
}
2368-
2369-
return true;
23702360
}
23712361
catch (ivx::RuntimeError & e)
23722362
{
2373-
CV_Error(CV_StsInternal, e.what());
2374-
return false;
2363+
VX_DbgThrow(e.what());
23752364
}
23762365
catch (ivx::WrapperError & e)
23772366
{
2378-
CV_Error(CV_StsInternal, e.what());
2379-
return false;
2367+
VX_DbgThrow(e.what());
23802368
}
2369+
2370+
return true;
23812371
}
23822372
#endif
23832373

@@ -2505,10 +2495,8 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
25052495

25062496
Mat src = _src.getMat(), mask = _mask.getMat();
25072497

2508-
#ifdef HAVE_OPENVX
2509-
if (openvx_minMaxIdx(src, minVal, maxVal, minIdx, maxIdx, mask))
2510-
return;
2511-
#endif
2498+
CV_OVX_RUN(true,
2499+
openvx_minMaxIdx(src, minVal, maxVal, minIdx, maxIdx, mask))
25122500

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

modules/imgproc/src/accum.cpp

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@
4545
#include "opencl_kernels_imgproc.hpp"
4646
#include "opencv2/core/hal/intrin.hpp"
4747

48-
#ifdef HAVE_OPENVX
49-
#define IVX_USE_OPENCV
50-
#define IVX_HIDE_INFO_WARNINGS
51-
#include "ivx.hpp"
52-
#endif
48+
#include "opencv2/core/openvx/ovx_defs.hpp"
5349

5450
namespace cv
5551
{
@@ -1993,13 +1989,11 @@ static bool openvx_accumulate(InputArray _src, InputOutputArray _dst, InputArray
19931989
}
19941990
catch (ivx::RuntimeError & e)
19951991
{
1996-
CV_Error(CV_StsInternal, e.what());
1997-
return false;
1992+
VX_DbgThrow(e.what());
19981993
}
19991994
catch (ivx::WrapperError & e)
20001995
{
2001-
CV_Error(CV_StsInternal, e.what());
2002-
return false;
1996+
VX_DbgThrow(e.what());
20031997
}
20041998

20051999
return true;
@@ -2023,12 +2017,8 @@ void cv::accumulate( InputArray _src, InputOutputArray _dst, InputArray _mask )
20232017
CV_IPP_RUN((_src.dims() <= 2 || (_src.isContinuous() && _dst.isContinuous() && (_mask.empty() || _mask.isContinuous()))),
20242018
ipp_accumulate(_src, _dst, _mask));
20252019

2026-
#ifdef HAVE_OPENVX
2027-
if(openvx_accumulate(_src, _dst, _mask, 0.0, VX_ACCUMULATE_OP))
2028-
{
2029-
return;
2030-
}
2031-
#endif
2020+
CV_OVX_RUN(_src.dims() <= 2,
2021+
openvx_accumulate(_src, _dst, _mask, 0.0, VX_ACCUMULATE_OP))
20322022

20332023
Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
20342024

@@ -2126,12 +2116,8 @@ void cv::accumulateSquare( InputArray _src, InputOutputArray _dst, InputArray _m
21262116
CV_IPP_RUN((_src.dims() <= 2 || (_src.isContinuous() && _dst.isContinuous() && (_mask.empty() || _mask.isContinuous()))),
21272117
ipp_accumulate_square(_src, _dst, _mask));
21282118

2129-
#ifdef HAVE_OPENVX
2130-
if(openvx_accumulate(_src, _dst, _mask, 0.0, VX_ACCUMULATE_SQUARE_OP))
2131-
{
2132-
return;
2133-
}
2134-
#endif
2119+
CV_OVX_RUN(_src.dims() <= 2,
2120+
openvx_accumulate(_src, _dst, _mask, 0.0, VX_ACCUMULATE_SQUARE_OP))
21352121

21362122
Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
21372123

@@ -2334,12 +2320,8 @@ void cv::accumulateWeighted( InputArray _src, InputOutputArray _dst,
23342320

23352321
CV_IPP_RUN((_src.dims() <= 2 || (_src.isContinuous() && _dst.isContinuous() && _mask.isContinuous())), ipp_accumulate_weighted(_src, _dst, alpha, _mask));
23362322

2337-
#ifdef HAVE_OPENVX
2338-
if(openvx_accumulate(_src, _dst, _mask, alpha, VX_ACCUMULATE_WEIGHTED_OP))
2339-
{
2340-
return;
2341-
}
2342-
#endif
2323+
CV_OVX_RUN(_src.dims() <= 2,
2324+
openvx_accumulate(_src, _dst, _mask, alpha, VX_ACCUMULATE_WEIGHTED_OP))
23432325

23442326
Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
23452327

modules/imgproc/src/canny.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -822,13 +822,11 @@ static bool openvx_canny(const Mat& src, Mat& dst, int loVal, int hiVal, int kSi
822822
}
823823
catch(const WrapperError& e)
824824
{
825-
//CV_DbgAssert(!"openvx_canny - WrapperError");
826-
return false;
825+
VX_DbgThrow(e.what());
827826
}
828827
catch(const RuntimeError& e)
829828
{
830-
//CV_DbgAssert(!"openvx_canny - RuntimeError");
831-
return false;
829+
VX_DbgThrow(e.what());
832830
}
833831

834832
return true;
@@ -877,7 +875,7 @@ void Canny( InputArray _src, OutputArray _dst,
877875
cvFloor(low_thresh),
878876
cvFloor(high_thresh),
879877
aperture_size,
880-
L2gradient ) );
878+
L2gradient ) )
881879

882880
#ifdef HAVE_TEGRA_OPTIMIZATION
883881
if (tegra::useTegra() && tegra::canny(src, dst, low_thresh, high_thresh, aperture_size, L2gradient))

modules/imgproc/src/deriv.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@
4343
#include "precomp.hpp"
4444
#include "opencl_kernels_imgproc.hpp"
4545

46-
#ifdef HAVE_OPENVX
47-
#define IVX_HIDE_INFO_WARNINGS
48-
#define IVX_USE_OPENCV
49-
#include "ivx.hpp"
50-
#endif
46+
#include "opencv2/core/openvx/ovx_defs.hpp"
5147

5248
/****************************************************************************************\
5349
Sobel & Scharr Derivative Filters
@@ -293,18 +289,17 @@ namespace cv
293289
ivx::IVX_CHECK_STATUS(vxuConvolve(ctx, ia, cnv, ib));
294290
}
295291
ctx.setImmediateBorder(prevBorder);
296-
return true;
297292
}
298293
catch (ivx::RuntimeError & e)
299294
{
300-
CV_Error(CV_StsInternal, e.what());
301-
return false;
295+
VX_DbgThrow(e.what());
302296
}
303297
catch (ivx::WrapperError & e)
304298
{
305-
CV_Error(CV_StsInternal, e.what());
306-
return false;
299+
VX_DbgThrow(e.what());
307300
}
301+
302+
return true;
308303
}
309304
}
310305
#endif
@@ -729,10 +724,8 @@ void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy,
729724
}
730725
#endif
731726

732-
#ifdef HAVE_OPENVX
733-
if (openvx_sobel(_src, _dst, dx, dy, ksize, scale, delta, borderType))
734-
return;
735-
#endif
727+
CV_OVX_RUN(true,
728+
openvx_sobel(_src, _dst, dx, dy, ksize, scale, delta, borderType))
736729

737730
CV_IPP_RUN(!(ocl::useOpenCL() && _dst.isUMat()), ipp_sobel(_src, _dst, ddepth, dx, dy, ksize, scale, delta, borderType));
738731

modules/imgproc/src/histogram.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,13 +1307,11 @@ namespace cv
13071307
}
13081308
catch (ivx::RuntimeError & e)
13091309
{
1310-
CV_Error(CV_StsInternal, e.what());
1311-
return false;
1310+
VX_DbgThrow(e.what());
13121311
}
13131312
catch (ivx::WrapperError & e)
13141313
{
1315-
CV_Error(CV_StsInternal, e.what());
1316-
return false;
1314+
VX_DbgThrow(e.what());
13171315
}
13181316

13191317
return true;
@@ -1379,7 +1377,7 @@ void cv::calcHist( const Mat* images, int nimages, const int* channels,
13791377
nimages == 1 && images[0].type() == CV_8UC1 && dims == 1 && _mask.getMat().empty() &&
13801378
(!channels || channels[0] == 0) && !accumulate && uniform &&
13811379
ranges && ranges[0],
1382-
openvx_calchist(images[0], _hist, histSize[0], ranges[0]));
1380+
openvx_calchist(images[0], _hist, histSize[0], ranges[0]))
13831381

13841382
CV_IPP_RUN(nimages == 1 && images[0].type() == CV_8UC1 && dims == 1 && channels &&
13851383
channels[0] == 0 && _mask.getMat().empty() && images[0].dims <= 2 &&
@@ -3791,13 +3789,11 @@ static bool openvx_equalize_hist(Mat srcMat, Mat dstMat)
37913789
}
37923790
catch (RuntimeError & e)
37933791
{
3794-
CV_Error(CV_StsInternal, e.what());
3795-
return false;
3792+
VX_DbgThrow(e.what());
37963793
}
37973794
catch (WrapperError & e)
37983795
{
3799-
CV_Error(CV_StsInternal, e.what());
3800-
return false;
3796+
VX_DbgThrow(e.what());
38013797
}
38023798

38033799
return true;
@@ -3821,12 +3817,8 @@ void cv::equalizeHist( InputArray _src, OutputArray _dst )
38213817
_dst.create( src.size(), src.type() );
38223818
Mat dst = _dst.getMat();
38233819

3824-
#ifdef HAVE_OPENVX
3825-
if(openvx_equalize_hist(src, dst))
3826-
{
3827-
return;
3828-
}
3829-
#endif
3820+
CV_OVX_RUN(true,
3821+
openvx_equalize_hist(src, dst))
38303822

38313823
Mutex histogramLockInstance;
38323824

0 commit comments

Comments
 (0)