Skip to content

Commit 4b82750

Browse files
committed
Merge pull request opencv#10058 from ElenaGvozdeva:eg/HAL
2 parents 7933fff + 7bfb380 commit 4b82750

File tree

5 files changed

+103
-21
lines changed

5 files changed

+103
-21
lines changed

modules/imgproc/perf/perf_blur.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ typedef perf::TestBaseWithParam<Size_MatType_BorderType3x3_t> Size_MatType_Borde
4343
typedef std::tr1::tuple<Size, MatType, BorderType> Size_MatType_BorderType_t;
4444
typedef perf::TestBaseWithParam<Size_MatType_BorderType_t> Size_MatType_BorderType;
4545

46+
typedef std::tr1::tuple<Size, int, BorderType3x3> Size_ksize_BorderType_t;
47+
typedef perf::TestBaseWithParam<Size_ksize_BorderType_t> Size_ksize_BorderType;
48+
4649
PERF_TEST_P(Size_MatType_BorderType3x3, gaussianBlur3x3,
4750
testing::Combine(
4851
testing::Values(szODD, szQVGA, szVGA, sz720p),
@@ -134,6 +137,28 @@ PERF_TEST_P(Size_MatType_BorderType3x3, box3x3,
134137
SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
135138
}
136139

140+
PERF_TEST_P(Size_ksize_BorderType, box_CV8U_CV16U,
141+
testing::Combine(
142+
testing::Values(szODD, szQVGA, szVGA, sz720p),
143+
testing::Values(3, 5, 15),
144+
BorderType3x3::all()
145+
)
146+
)
147+
{
148+
Size size = get<0>(GetParam());
149+
int ksize = get<1>(GetParam());
150+
BorderType3x3 btype = get<2>(GetParam());
151+
152+
Mat src(size, CV_8UC1);
153+
Mat dst(size, CV_16UC1);
154+
155+
declare.in(src, WARMUP_RNG).out(dst);
156+
157+
TEST_CYCLE() boxFilter(src, dst, CV_16UC1, Size(ksize, ksize), Point(-1,-1), false, btype);
158+
159+
SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
160+
}
161+
137162
PERF_TEST_P(Size_MatType_BorderType3x3, box3x3_inplace,
138163
testing::Combine(
139164
testing::Values(szODD, szQVGA, szVGA, sz720p),

modules/imgproc/src/filter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4333,7 +4333,7 @@ static bool ocl_sepFilter2D_SinglePass(InputArray _src, OutputArray _dst,
43334333
return k.run(2, gt2, lt2, false);
43344334
}
43354335

4336-
static bool ocl_sepFilter2D( InputArray _src, OutputArray _dst, int ddepth,
4336+
bool ocl_sepFilter2D( InputArray _src, OutputArray _dst, int ddepth,
43374337
InputArray _kernelX, InputArray _kernelY, Point anchor,
43384338
double delta, int borderType )
43394339
{

modules/imgproc/src/filter.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ namespace cv
5050
int SymmColumnVec_32f_Symm_AVX(const float** src, const float* ky, float* dst, float delta, int width, int ksize2);
5151
int SymmColumnVec_32f_Unsymm_AVX(const float** src, const float* ky, float* dst, float delta, int width, int ksize2);
5252
#endif
53+
54+
#ifdef HAVE_OPENCL
55+
bool ocl_sepFilter2D( InputArray _src, OutputArray _dst, int ddepth,
56+
InputArray _kernelX, InputArray _kernelY, Point anchor,
57+
double delta, int borderType );
58+
#endif
5359
}
5460

5561
#endif

modules/imgproc/src/hal_replacement.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,43 @@ inline int hal_ni_threshold(const uchar* src_data, size_t src_step, uchar* dst_d
664664
#define cv_hal_threshold hal_ni_threshold
665665
//! @endcond
666666

667+
/**
668+
@brief Calculate box filter
669+
@param src_data,src_step Source image
670+
@param dst_data,dst_step Destination image
671+
@param width,height Source image dimensions
672+
@param src_depth,dst_depth Depths of source and destination image
673+
@param cn Number of channels
674+
@param margin_left,margin_top,margin_right,margin_bottom Margins for source image
675+
@param ksize_width,ksize_height Size of kernel
676+
@param anchor_x,anchor_y Anchor point
677+
@param normalize If true then result is normalized
678+
@param border_type Border type
679+
*/
680+
inline int hal_ni_boxFilter(const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int src_depth, int dst_depth, int cn, int margin_left, int margin_top, int margin_right, int margin_bottom, size_t ksize_width, size_t ksize_height, int anchor_x, int anchor_y, bool normalize, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
681+
682+
//! @cond IGNORED
683+
#define cv_hal_boxFilter hal_ni_boxFilter
684+
//! @endcond
685+
686+
/**
687+
@brief Blurs an image using a Gaussian filter.
688+
@param src_data,src_step Source image
689+
@param dst_data,dst_step Destination image
690+
@param width,height Source image dimensions
691+
@param depth Depth of source and destination image
692+
@param cn Number of channels
693+
@param margin_left,margin_top,margin_right,margin_bottom Margins for source image
694+
@param ksize_width,ksize_height Size of kernel
695+
@param sigmaX,sigmaY Gaussian kernel standard deviation.
696+
@param border_type Border type
697+
*/
698+
inline int hal_ni_gaussianBlur(const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int depth, int cn, size_t margin_left, size_t margin_top, size_t margin_right, size_t margin_bottom, size_t ksize_width, size_t ksize_height, double sigmaX, double sigmaY, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
699+
700+
//! @cond IGNORED
701+
#define cv_hal_gaussianBlur hal_ni_gaussianBlur
702+
//! @endcond
703+
667704
//! @}
668705

669706
#if defined __GNUC__

modules/imgproc/src/smooth.cpp

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
#include "opencv2/core/openvx/ovx_defs.hpp"
4949

50+
#include "filter.hpp"
51+
5052
/*
5153
* This file includes the code, contributed by Simon Perreault
5254
* (the function icvMedianBlur_8u_O1)
@@ -1536,9 +1538,6 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth,
15361538

15371539
CV_OCL_RUN(_dst.isUMat(), ocl_boxFilter(_src, _dst, ddepth, ksize, anchor, borderType, normalize))
15381540

1539-
CV_OVX_RUN(true,
1540-
openvx_boxfilter(_src, _dst, ddepth, ksize, anchor, normalize, borderType))
1541-
15421541
Mat src = _src.getMat();
15431542
int stype = src.type(), sdepth = CV_MAT_DEPTH(stype), cn = CV_MAT_CN(stype);
15441543
if( ddepth < 0 )
@@ -1552,17 +1551,21 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth,
15521551
if( src.cols == 1 )
15531552
ksize.width = 1;
15541553
}
1555-
#ifdef HAVE_TEGRA_OPTIMIZATION
1556-
if ( tegra::useTegra() && tegra::box(src, dst, ksize, anchor, normalize, borderType) )
1557-
return;
1558-
#endif
1559-
1560-
CV_IPP_RUN_FAST(ipp_boxfilter(src, dst, ksize, anchor, normalize, borderType));
15611554

15621555
Point ofs;
15631556
Size wsz(src.cols, src.rows);
15641557
if(!(borderType&BORDER_ISOLATED))
15651558
src.locateROI( wsz, ofs );
1559+
1560+
CALL_HAL(boxFilter, cv_hal_boxFilter, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, ddepth, cn,
1561+
ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height,
1562+
anchor.x, anchor.y, normalize, borderType&~BORDER_ISOLATED);
1563+
1564+
CV_OVX_RUN(true,
1565+
openvx_boxfilter(src, dst, ddepth, ksize, anchor, normalize, borderType))
1566+
1567+
CV_IPP_RUN_FAST(ipp_boxfilter(src, dst, ksize, anchor, normalize, borderType));
1568+
15661569
borderType = (borderType&~BORDER_ISOLATED);
15671570

15681571
Ptr<FilterEngine> f = createBoxFilter( src.type(), dst.type(),
@@ -2093,29 +2096,40 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize,
20932096
return;
20942097
}
20952098

2096-
CV_OVX_RUN(true,
2097-
openvx_gaussianBlur(_src, _dst, ksize, sigma1, sigma2, borderType))
2098-
2099-
#ifdef HAVE_TEGRA_OPTIMIZATION
2100-
Mat src = _src.getMat();
2101-
Mat dst = _dst.getMat();
2102-
if(sigma1 == 0 && sigma2 == 0 && tegra::useTegra() && tegra::gaussian(src, dst, ksize, borderType))
2103-
return;
2104-
#endif
21052099
bool useOpenCL = (ocl::isOpenCLActivated() && _dst.isUMat() && _src.dims() <= 2 &&
21062100
((ksize.width == 3 && ksize.height == 3) ||
21072101
(ksize.width == 5 && ksize.height == 5)) &&
21082102
_src.rows() > ksize.height && _src.cols() > ksize.width);
21092103
(void)useOpenCL;
21102104

2111-
CV_IPP_RUN(!useOpenCL, ipp_GaussianBlur( _src, _dst, ksize, sigma1, sigma2, borderType));
2105+
int sdepth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
21122106

21132107
Mat kx, ky;
21142108
createGaussianKernels(kx, ky, type, ksize, sigma1, sigma2);
21152109

21162110
CV_OCL_RUN(useOpenCL, ocl_GaussianBlur_8UC1(_src, _dst, ksize, CV_MAT_DEPTH(type), kx, ky, borderType));
21172111

2118-
sepFilter2D(_src, _dst, CV_MAT_DEPTH(type), kx, ky, Point(-1,-1), 0, borderType );
2112+
CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2 && (size_t)_src.rows() > kx.total() && (size_t)_src.cols() > kx.total(),
2113+
ocl_sepFilter2D(_src, _dst, sdepth, kx, ky, Point(-1, -1), 0, borderType))
2114+
2115+
Mat src = _src.getMat();
2116+
Mat dst = _dst.getMat();
2117+
2118+
Point ofs;
2119+
Size wsz(src.cols, src.rows);
2120+
if(!(borderType & BORDER_ISOLATED))
2121+
src.locateROI( wsz, ofs );
2122+
2123+
CALL_HAL(gaussianBlur, cv_hal_gaussianBlur, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, cn,
2124+
ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height,
2125+
sigma1, sigma2, borderType&~BORDER_ISOLATED);
2126+
2127+
CV_OVX_RUN(true,
2128+
openvx_gaussianBlur(src, dst, ksize, sigma1, sigma2, borderType))
2129+
2130+
CV_IPP_RUN_FAST(ipp_GaussianBlur(src, dst, ksize, sigma1, sigma2, borderType));
2131+
2132+
sepFilter2D(src, dst, sdepth, kx, ky, Point(-1, -1), 0, borderType);
21192133
}
21202134

21212135
/****************************************************************************************\

0 commit comments

Comments
 (0)