From cb9e110adb919e2023dec3807c979330b6717bde Mon Sep 17 00:00:00 2001 From: elenagvo Date: Wed, 1 Nov 2017 12:57:53 +0300 Subject: [PATCH 1/8] add HAL for BoxFilter --- modules/imgproc/src/hal_replacement.hpp | 19 +++++++++++++++++++ modules/imgproc/src/smooth.cpp | 18 ++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/modules/imgproc/src/hal_replacement.hpp b/modules/imgproc/src/hal_replacement.hpp index be05644067..00e6a94543 100644 --- a/modules/imgproc/src/hal_replacement.hpp +++ b/modules/imgproc/src/hal_replacement.hpp @@ -664,6 +664,25 @@ inline int hal_ni_threshold(const uchar* src_data, size_t src_step, uchar* dst_d #define cv_hal_threshold hal_ni_threshold //! @endcond +/** + @brief Calculate box filter + @param src_depth, dst_depth Depths of source and destination image + @param src_data, src_step Source image + @param dst_data, dst_step Destination image + @param ksize Size of kernel + @param anchor Anchor point + @param normalize If true then result is normalized + @param border_type Border type + @param margins Margins for source image + @param width, height Source image dimensions + @param cn Number of channels +*/ +inline int hal_ni_boxFilter(int src_depth, int dst_depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, CvSize ksize, CvPoint anchor, bool normalize, int border_type, CvRect margins, int width, int height, int cn) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } + +//! @cond IGNORED +#define cv_hal_boxFilter hal_ni_boxFilter +//! @endcond + //! @} #if defined __GNUC__ diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 54c15e28ca..45ec278257 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1552,12 +1552,6 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, if( src.cols == 1 ) ksize.width = 1; } -#ifdef HAVE_TEGRA_OPTIMIZATION - if ( tegra::useTegra() && tegra::box(src, dst, ksize, anchor, normalize, borderType) ) - return; -#endif - - CV_IPP_RUN_FAST(ipp_boxfilter(src, dst, ksize, anchor, normalize, borderType)); Point ofs; Size wsz(src.cols, src.rows); @@ -1565,6 +1559,18 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, src.locateROI( wsz, ofs ); borderType = (borderType&~BORDER_ISOLATED); + CvRect margin = cvRect(ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y); + + CALL_HAL(boxFilter, cv_hal_boxFilter, sdepth, ddepth, src.ptr(), src.step, dst.ptr(), dst.step, + (CvSize)(ksize), (CvPoint)(anchor), normalize, borderType, margin, src.cols, src.rows, cn); + +#ifdef HAVE_TEGRA_OPTIMIZATION + if ( tegra::useTegra() && tegra::box(src, dst, ksize, anchor, normalize, borderType) ) + return; +#endif + + CV_IPP_RUN_FAST(ipp_boxfilter(src, dst, ksize, anchor, normalize, borderType)); + Ptr f = createBoxFilter( src.type(), dst.type(), ksize, anchor, normalize, borderType ); From c2c7333107be559eb3fa6097d5caf97b71e15a7f Mon Sep 17 00:00:00 2001 From: elenagvo Date: Wed, 1 Nov 2017 16:45:07 +0300 Subject: [PATCH 2/8] add hal for GaussianBlur --- modules/imgproc/src/hal_replacement.hpp | 30 ++++++++++++++++++++----- modules/imgproc/src/smooth.cpp | 20 +++++++++++++++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/modules/imgproc/src/hal_replacement.hpp b/modules/imgproc/src/hal_replacement.hpp index 00e6a94543..14baa9d526 100644 --- a/modules/imgproc/src/hal_replacement.hpp +++ b/modules/imgproc/src/hal_replacement.hpp @@ -666,23 +666,41 @@ inline int hal_ni_threshold(const uchar* src_data, size_t src_step, uchar* dst_d /** @brief Calculate box filter - @param src_depth, dst_depth Depths of source and destination image - @param src_data, src_step Source image - @param dst_data, dst_step Destination image + @param src_depth,dst_depth Depths of source and destination image + @param src_data,src_step Source image + @param dst_data,dst_step Destination image + @param width,height Source image dimensions + @param margins Margins for source image @param ksize Size of kernel @param anchor Anchor point @param normalize If true then result is normalized @param border_type Border type - @param margins Margins for source image - @param width, height Source image dimensions @param cn Number of channels */ -inline int hal_ni_boxFilter(int src_depth, int dst_depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, CvSize ksize, CvPoint anchor, bool normalize, int border_type, CvRect margins, int width, int height, int cn) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_boxFilter(int src_depth, int dst_depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int cn, CvRect margins, CvSize ksize, CvPoint anchor, bool normalize, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } //! @cond IGNORED #define cv_hal_boxFilter hal_ni_boxFilter //! @endcond +/** + @brief Blurs an image using a Gaussian filter. + @param src_depth,dst_depth Depths of source and destination image + @param src_data,src_step Source image + @param dst_data,dst_step Destination image + @param width,height Source image dimensions + @param margins Margins for source image + @param ksize Size of kernel + @param sigmaX,sigmaY Gaussian kernel standard deviation. + @param border_type Border type + @param cn Number of channels +*/ +inline int hal_ni_gaussianBlur(int depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int cn, CvRect margins, CvSize ksize, double sigmaX, double sigmaY, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } + +//! @cond IGNORED +#define cv_hal_gaussianBlur hal_ni_gaussianBlur +//! @endcond + //! @} #if defined __GNUC__ diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 45ec278257..a296242baf 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1561,8 +1561,8 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, CvRect margin = cvRect(ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y); - CALL_HAL(boxFilter, cv_hal_boxFilter, sdepth, ddepth, src.ptr(), src.step, dst.ptr(), dst.step, - (CvSize)(ksize), (CvPoint)(anchor), normalize, borderType, margin, src.cols, src.rows, cn); + CALL_HAL(boxFilter, cv_hal_boxFilter, sdepth, ddepth, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, cn, + margin, (CvSize)(ksize), (CvPoint)(anchor), normalize, borderType); #ifdef HAVE_TEGRA_OPTIMIZATION if ( tegra::useTegra() && tegra::box(src, dst, ksize, anchor, normalize, borderType) ) @@ -2114,6 +2114,22 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, _src.rows() > ksize.height && _src.cols() > ksize.width); (void)useOpenCL; + Mat src = _src.getMat(); + Mat dst = _dst.getMat(); + + int sdepth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); + + Point ofs; + Size wsz(src.cols, src.rows); + if(!(borderType & BORDER_ISOLATED)) + src.locateROI( wsz, ofs ); + borderType = (borderType&~BORDER_ISOLATED); + + CvRect margin = cvRect(ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y); + + CALL_HAL(gaussianBlur, cv_hal_gaussianBlur, sdepth, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, cn, + margin, (CvSize)(ksize), sigma1, sigma2, borderType); + CV_IPP_RUN(!useOpenCL, ipp_GaussianBlur( _src, _dst, ksize, sigma1, sigma2, borderType)); Mat kx, ky; From a25c443d1f99285c0986fd197d4b4a0c663571f1 Mon Sep 17 00:00:00 2001 From: elenagvo Date: Thu, 9 Nov 2017 14:13:55 +0300 Subject: [PATCH 3/8] add perf test for boxFilter CV8U to CV16U --- modules/imgproc/perf/perf_blur.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/imgproc/perf/perf_blur.cpp b/modules/imgproc/perf/perf_blur.cpp index 2a284dc5b9..956782e38c 100644 --- a/modules/imgproc/perf/perf_blur.cpp +++ b/modules/imgproc/perf/perf_blur.cpp @@ -43,6 +43,9 @@ typedef perf::TestBaseWithParam Size_MatType_Borde typedef std::tr1::tuple Size_MatType_BorderType_t; typedef perf::TestBaseWithParam Size_MatType_BorderType; +typedef std::tr1::tuple Size_ksize_BorderType_t; +typedef perf::TestBaseWithParam Size_ksize_BorderType; + PERF_TEST_P(Size_MatType_BorderType3x3, gaussianBlur3x3, testing::Combine( testing::Values(szODD, szQVGA, szVGA, sz720p), @@ -134,6 +137,28 @@ PERF_TEST_P(Size_MatType_BorderType3x3, box3x3, SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); } +PERF_TEST_P(Size_ksize_BorderType, box_CV8U_CV16U, + testing::Combine( + testing::Values(szODD, szQVGA, szVGA, sz720p), + testing::Values(3, 5, 15), + BorderType3x3::all() + ) + ) +{ + Size size = get<0>(GetParam()); + int ksize = get<1>(GetParam()); + BorderType3x3 btype = get<2>(GetParam()); + + Mat src(size, CV_8UC1); + Mat dst(size, CV_16UC1); + + declare.in(src, WARMUP_RNG).out(dst); + + TEST_CYCLE() boxFilter(src, dst, CV_16UC1, Size(ksize, ksize), Point(-1,-1), false, btype); + + SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); +} + PERF_TEST_P(Size_MatType_BorderType3x3, box3x3_inplace, testing::Combine( testing::Values(szODD, szQVGA, szVGA, sz720p), From ce6597562509d084747eaf3a74599d090b727adf Mon Sep 17 00:00:00 2001 From: elenagvo Date: Fri, 10 Nov 2017 11:39:44 +0300 Subject: [PATCH 4/8] call HAL for GaussianBlur is fixed --- modules/imgproc/src/hal_replacement.hpp | 6 +++--- modules/imgproc/src/smooth.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/imgproc/src/hal_replacement.hpp b/modules/imgproc/src/hal_replacement.hpp index 14baa9d526..261c646876 100644 --- a/modules/imgproc/src/hal_replacement.hpp +++ b/modules/imgproc/src/hal_replacement.hpp @@ -670,12 +670,12 @@ inline int hal_ni_threshold(const uchar* src_data, size_t src_step, uchar* dst_d @param src_data,src_step Source image @param dst_data,dst_step Destination image @param width,height Source image dimensions + @param cn Number of channels @param margins Margins for source image @param ksize Size of kernel @param anchor Anchor point @param normalize If true then result is normalized @param border_type Border type - @param cn Number of channels */ inline int hal_ni_boxFilter(int src_depth, int dst_depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int cn, CvRect margins, CvSize ksize, CvPoint anchor, bool normalize, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } @@ -685,15 +685,15 @@ inline int hal_ni_boxFilter(int src_depth, int dst_depth, const uchar* src_data, /** @brief Blurs an image using a Gaussian filter. - @param src_depth,dst_depth Depths of source and destination image + @param depth Depth of source and destination image @param src_data,src_step Source image @param dst_data,dst_step Destination image @param width,height Source image dimensions + @param cn Number of channels @param margins Margins for source image @param ksize Size of kernel @param sigmaX,sigmaY Gaussian kernel standard deviation. @param border_type Border type - @param cn Number of channels */ inline int hal_ni_gaussianBlur(int depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int cn, CvRect margins, CvSize ksize, double sigmaX, double sigmaY, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index a296242baf..07fa6040c5 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -2102,9 +2102,10 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, CV_OVX_RUN(true, openvx_gaussianBlur(_src, _dst, ksize, sigma1, sigma2, borderType)) -#ifdef HAVE_TEGRA_OPTIMIZATION Mat src = _src.getMat(); Mat dst = _dst.getMat(); + +#ifdef HAVE_TEGRA_OPTIMIZATION if(sigma1 == 0 && sigma2 == 0 && tegra::useTegra() && tegra::gaussian(src, dst, ksize, borderType)) return; #endif @@ -2114,9 +2115,6 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, _src.rows() > ksize.height && _src.cols() > ksize.width); (void)useOpenCL; - Mat src = _src.getMat(); - Mat dst = _dst.getMat(); - int sdepth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); Point ofs; @@ -2130,6 +2128,9 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, CALL_HAL(gaussianBlur, cv_hal_gaussianBlur, sdepth, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, cn, margin, (CvSize)(ksize), sigma1, sigma2, borderType); + src.release(); + dst.release(); + CV_IPP_RUN(!useOpenCL, ipp_GaussianBlur( _src, _dst, ksize, sigma1, sigma2, borderType)); Mat kx, ky; From 7aadbc9607b80f6d0d318deb35479aba8e215ccb Mon Sep 17 00:00:00 2001 From: elenagvo Date: Mon, 13 Nov 2017 17:43:32 +0300 Subject: [PATCH 5/8] remove complex data structs --- modules/imgproc/src/hal_replacement.hpp | 14 +++++++------- modules/imgproc/src/smooth.cpp | 10 ++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/imgproc/src/hal_replacement.hpp b/modules/imgproc/src/hal_replacement.hpp index 261c646876..2531fc1ba0 100644 --- a/modules/imgproc/src/hal_replacement.hpp +++ b/modules/imgproc/src/hal_replacement.hpp @@ -671,13 +671,13 @@ inline int hal_ni_threshold(const uchar* src_data, size_t src_step, uchar* dst_d @param dst_data,dst_step Destination image @param width,height Source image dimensions @param cn Number of channels - @param margins Margins for source image - @param ksize Size of kernel - @param anchor Anchor point + @param margin_left,margin_top,margin_right,margin_bottom Margins for source image + @param ksize_width,ksize_height Size of kernel + @param anchor_x,anchor_y Anchor point @param normalize If true then result is normalized @param border_type Border type */ -inline int hal_ni_boxFilter(int src_depth, int dst_depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int cn, CvRect margins, CvSize ksize, CvPoint anchor, bool normalize, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_boxFilter(int src_depth, int dst_depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, 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; } //! @cond IGNORED #define cv_hal_boxFilter hal_ni_boxFilter @@ -690,12 +690,12 @@ inline int hal_ni_boxFilter(int src_depth, int dst_depth, const uchar* src_data, @param dst_data,dst_step Destination image @param width,height Source image dimensions @param cn Number of channels - @param margins Margins for source image - @param ksize Size of kernel + @param margin_left,margin_top,margin_right,margin_bottom Margins for source image + @param ksize_width,ksize_height Size of kernel @param sigmaX,sigmaY Gaussian kernel standard deviation. @param border_type Border type */ -inline int hal_ni_gaussianBlur(int depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int cn, CvRect margins, CvSize ksize, double sigmaX, double sigmaY, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_gaussianBlur(int depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, 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; } //! @cond IGNORED #define cv_hal_gaussianBlur hal_ni_gaussianBlur diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 07fa6040c5..2791051a99 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1559,10 +1559,9 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, src.locateROI( wsz, ofs ); borderType = (borderType&~BORDER_ISOLATED); - CvRect margin = cvRect(ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y); - CALL_HAL(boxFilter, cv_hal_boxFilter, sdepth, ddepth, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, cn, - margin, (CvSize)(ksize), (CvPoint)(anchor), normalize, borderType); + ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height, + anchor.x, anchor.y, normalize, borderType); #ifdef HAVE_TEGRA_OPTIMIZATION if ( tegra::useTegra() && tegra::box(src, dst, ksize, anchor, normalize, borderType) ) @@ -2123,10 +2122,9 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, src.locateROI( wsz, ofs ); borderType = (borderType&~BORDER_ISOLATED); - CvRect margin = cvRect(ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y); - CALL_HAL(gaussianBlur, cv_hal_gaussianBlur, sdepth, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, cn, - margin, (CvSize)(ksize), sigma1, sigma2, borderType); + ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height, + sigma1, sigma2, borderType); src.release(); dst.release(); From 0f12351a41d291a649bb81923c6f06e6cb886282 Mon Sep 17 00:00:00 2001 From: elenagvo Date: Tue, 14 Nov 2017 12:57:02 +0300 Subject: [PATCH 6/8] fix accelerators order --- modules/imgproc/src/filter.cpp | 2 +- modules/imgproc/src/filter.hpp | 6 ++++ modules/imgproc/src/smooth.cpp | 66 ++++++++++++++++------------------ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index e732ce5077..1302407a25 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -4333,7 +4333,7 @@ static bool ocl_sepFilter2D_SinglePass(InputArray _src, OutputArray _dst, return k.run(2, gt2, lt2, false); } -static bool ocl_sepFilter2D( InputArray _src, OutputArray _dst, int ddepth, +bool ocl_sepFilter2D( InputArray _src, OutputArray _dst, int ddepth, InputArray _kernelX, InputArray _kernelY, Point anchor, double delta, int borderType ) { diff --git a/modules/imgproc/src/filter.hpp b/modules/imgproc/src/filter.hpp index c878fea281..93f3f177e6 100644 --- a/modules/imgproc/src/filter.hpp +++ b/modules/imgproc/src/filter.hpp @@ -50,6 +50,12 @@ namespace cv int SymmColumnVec_32f_Symm_AVX(const float** src, const float* ky, float* dst, float delta, int width, int ksize2); int SymmColumnVec_32f_Unsymm_AVX(const float** src, const float* ky, float* dst, float delta, int width, int ksize2); #endif + +#ifdef HAVE_OPENCL + bool ocl_sepFilter2D( InputArray _src, OutputArray _dst, int ddepth, + InputArray _kernelX, InputArray _kernelY, Point anchor, + double delta, int borderType ); +#endif } #endif diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 2791051a99..0ca087c68d 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -47,6 +47,8 @@ #include "opencv2/core/openvx/ovx_defs.hpp" +#include "filter.hpp" + /* * This file includes the code, contributed by Simon Perreault * (the function icvMedianBlur_8u_O1) @@ -1536,9 +1538,6 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, CV_OCL_RUN(_dst.isUMat(), ocl_boxFilter(_src, _dst, ddepth, ksize, anchor, borderType, normalize)) - CV_OVX_RUN(true, - openvx_boxfilter(_src, _dst, ddepth, ksize, anchor, normalize, borderType)) - Mat src = _src.getMat(); int stype = src.type(), sdepth = CV_MAT_DEPTH(stype), cn = CV_MAT_CN(stype); if( ddepth < 0 ) @@ -1557,19 +1556,18 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, Size wsz(src.cols, src.rows); if(!(borderType&BORDER_ISOLATED)) src.locateROI( wsz, ofs ); - borderType = (borderType&~BORDER_ISOLATED); CALL_HAL(boxFilter, cv_hal_boxFilter, sdepth, ddepth, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, cn, ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height, - anchor.x, anchor.y, normalize, borderType); + anchor.x, anchor.y, normalize, borderType&~BORDER_ISOLATED); -#ifdef HAVE_TEGRA_OPTIMIZATION - if ( tegra::useTegra() && tegra::box(src, dst, ksize, anchor, normalize, borderType) ) - return; -#endif + CV_OVX_RUN(true, + openvx_boxfilter(_src, _dst, ddepth, ksize, anchor, normalize, borderType)) CV_IPP_RUN_FAST(ipp_boxfilter(src, dst, ksize, anchor, normalize, borderType)); + borderType = (borderType&~BORDER_ISOLATED); + Ptr f = createBoxFilter( src.type(), dst.type(), ksize, anchor, normalize, borderType ); @@ -2098,16 +2096,6 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, return; } - CV_OVX_RUN(true, - openvx_gaussianBlur(_src, _dst, ksize, sigma1, sigma2, borderType)) - - Mat src = _src.getMat(); - Mat dst = _dst.getMat(); - -#ifdef HAVE_TEGRA_OPTIMIZATION - if(sigma1 == 0 && sigma2 == 0 && tegra::useTegra() && tegra::gaussian(src, dst, ksize, borderType)) - return; -#endif bool useOpenCL = (ocl::isOpenCLActivated() && _dst.isUMat() && _src.dims() <= 2 && ((ksize.width == 3 && ksize.height == 3) || (ksize.width == 5 && ksize.height == 5)) && @@ -2116,27 +2104,35 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, int sdepth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); - Point ofs; - Size wsz(src.cols, src.rows); - if(!(borderType & BORDER_ISOLATED)) - src.locateROI( wsz, ofs ); - borderType = (borderType&~BORDER_ISOLATED); - - CALL_HAL(gaussianBlur, cv_hal_gaussianBlur, sdepth, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, cn, - ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height, - sigma1, sigma2, borderType); - - src.release(); - dst.release(); - - CV_IPP_RUN(!useOpenCL, ipp_GaussianBlur( _src, _dst, ksize, sigma1, sigma2, borderType)); - Mat kx, ky; createGaussianKernels(kx, ky, type, ksize, sigma1, sigma2); CV_OCL_RUN(useOpenCL, ocl_GaussianBlur_8UC1(_src, _dst, ksize, CV_MAT_DEPTH(type), kx, ky, borderType)); - sepFilter2D(_src, _dst, CV_MAT_DEPTH(type), kx, ky, Point(-1,-1), 0, borderType ); + CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2 && (size_t)_src.rows() > kx.total() && (size_t)_src.cols() > kx.total(), + ocl_sepFilter2D(_src, _dst, sdepth, kx, ky, Point(-1, -1), 0, borderType)) + + Mat src = _src.getMat(); + Mat dst = _dst.getMat(); + + Point ofs; + Size wsz(src.cols, src.rows); + if(!(borderType & BORDER_ISOLATED)) + src.locateROI( wsz, ofs ); + + CALL_HAL(gaussianBlur, cv_hal_gaussianBlur, sdepth, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, cn, + ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height, + sigma1, sigma2, borderType&~BORDER_ISOLATED); + + src.release(); + dst.release(); + + CV_OVX_RUN(true, + openvx_gaussianBlur(_src, _dst, ksize, sigma1, sigma2, borderType)) + + CV_IPP_RUN_FAST(ipp_GaussianBlur(_src, _dst, ksize, sigma1, sigma2, borderType)); + + sepFilter2D(_src, _dst, sdepth, kx, ky, Point(-1, -1), 0, borderType); } /****************************************************************************************\ From 81519537ae1311cc3dbe7415fa70f7bb1b67c017 Mon Sep 17 00:00:00 2001 From: elenagvo Date: Thu, 23 Nov 2017 13:46:32 +0300 Subject: [PATCH 7/8] fix the parameters order --- modules/imgproc/src/hal_replacement.hpp | 8 ++++---- modules/imgproc/src/smooth.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/imgproc/src/hal_replacement.hpp b/modules/imgproc/src/hal_replacement.hpp index 2531fc1ba0..d48090506f 100644 --- a/modules/imgproc/src/hal_replacement.hpp +++ b/modules/imgproc/src/hal_replacement.hpp @@ -666,10 +666,10 @@ inline int hal_ni_threshold(const uchar* src_data, size_t src_step, uchar* dst_d /** @brief Calculate box filter - @param src_depth,dst_depth Depths of source and destination image @param src_data,src_step Source image @param dst_data,dst_step Destination image @param width,height Source image dimensions + @param src_depth,dst_depth Depths of source and destination image @param cn Number of channels @param margin_left,margin_top,margin_right,margin_bottom Margins for source image @param ksize_width,ksize_height Size of kernel @@ -677,7 +677,7 @@ inline int hal_ni_threshold(const uchar* src_data, size_t src_step, uchar* dst_d @param normalize If true then result is normalized @param border_type Border type */ -inline int hal_ni_boxFilter(int src_depth, int dst_depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, 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; } +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; } //! @cond IGNORED #define cv_hal_boxFilter hal_ni_boxFilter @@ -685,17 +685,17 @@ inline int hal_ni_boxFilter(int src_depth, int dst_depth, const uchar* src_data, /** @brief Blurs an image using a Gaussian filter. - @param depth Depth of source and destination image @param src_data,src_step Source image @param dst_data,dst_step Destination image @param width,height Source image dimensions + @param depth Depth of source and destination image @param cn Number of channels @param margin_left,margin_top,margin_right,margin_bottom Margins for source image @param ksize_width,ksize_height Size of kernel @param sigmaX,sigmaY Gaussian kernel standard deviation. @param border_type Border type */ -inline int hal_ni_gaussianBlur(int depth, const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, 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; } +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; } //! @cond IGNORED #define cv_hal_gaussianBlur hal_ni_gaussianBlur diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 0ca087c68d..a6c4f6be03 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1557,7 +1557,7 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, if(!(borderType&BORDER_ISOLATED)) src.locateROI( wsz, ofs ); - CALL_HAL(boxFilter, cv_hal_boxFilter, sdepth, ddepth, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, cn, + CALL_HAL(boxFilter, cv_hal_boxFilter, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, ddepth, cn, ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height, anchor.x, anchor.y, normalize, borderType&~BORDER_ISOLATED); @@ -2120,7 +2120,7 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, if(!(borderType & BORDER_ISOLATED)) src.locateROI( wsz, ofs ); - CALL_HAL(gaussianBlur, cv_hal_gaussianBlur, sdepth, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, cn, + CALL_HAL(gaussianBlur, cv_hal_gaussianBlur, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, cn, ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height, sigma1, sigma2, borderType&~BORDER_ISOLATED); From 7bfb38055c16e8f5c32be891e4364fa749e37e8d Mon Sep 17 00:00:00 2001 From: elenagvo Date: Tue, 28 Nov 2017 17:11:16 +0300 Subject: [PATCH 8/8] remove matrix release --- modules/imgproc/src/smooth.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index a6c4f6be03..afe45af2c3 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1562,7 +1562,7 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, anchor.x, anchor.y, normalize, borderType&~BORDER_ISOLATED); CV_OVX_RUN(true, - openvx_boxfilter(_src, _dst, ddepth, ksize, anchor, normalize, borderType)) + openvx_boxfilter(src, dst, ddepth, ksize, anchor, normalize, borderType)) CV_IPP_RUN_FAST(ipp_boxfilter(src, dst, ksize, anchor, normalize, borderType)); @@ -2124,15 +2124,12 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height, sigma1, sigma2, borderType&~BORDER_ISOLATED); - src.release(); - dst.release(); - CV_OVX_RUN(true, - openvx_gaussianBlur(_src, _dst, ksize, sigma1, sigma2, borderType)) + openvx_gaussianBlur(src, dst, ksize, sigma1, sigma2, borderType)) - CV_IPP_RUN_FAST(ipp_GaussianBlur(_src, _dst, ksize, sigma1, sigma2, borderType)); + CV_IPP_RUN_FAST(ipp_GaussianBlur(src, dst, ksize, sigma1, sigma2, borderType)); - sepFilter2D(_src, _dst, sdepth, kx, ky, Point(-1, -1), 0, borderType); + sepFilter2D(src, dst, sdepth, kx, ky, Point(-1, -1), 0, borderType); } /****************************************************************************************\