From 6185f7209e86e33f426c640f706825cddbd5f190 Mon Sep 17 00:00:00 2001 From: Elena Gvozdeva <6037903+ElenaGvozdeva@users.noreply.github.com> Date: Fri, 8 Dec 2017 16:36:24 +0300 Subject: [PATCH] Merge pull request #10172 from ElenaGvozdeva:eg/HAL_sobel * add HAL for SobelFilter * add HAL for pyrDown * add HAL for Scharr --- modules/imgproc/src/deriv.cpp | 72 ++++++++++++++----------- modules/imgproc/src/hal_replacement.hpp | 55 +++++++++++++++++++ modules/imgproc/src/pyramids.cpp | 2 + 3 files changed, 98 insertions(+), 31 deletions(-) diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index 96c8f408cb..d08b08c44f 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -44,6 +44,7 @@ #include "opencl_kernels_imgproc.hpp" #include "opencv2/core/openvx/ovx_defs.hpp" +#include "filter.hpp" /****************************************************************************************\ Sobel & Scharr Derivative Filters @@ -421,22 +422,6 @@ void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy, int dtype = CV_MAKE_TYPE(ddepth, cn); _dst.create( _src.size(), dtype ); -#ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::useTegra() && scale == 1.0 && delta == 0) - { - Mat src = _src.getMat(), dst = _dst.getMat(); - if (ksize == 3 && tegra::sobel3x3(src, dst, dx, dy, borderType)) - return; - if (ksize == -1 && tegra::scharr(src, dst, dx, dy, borderType)) - return; - } -#endif - - CV_OVX_RUN(true, - openvx_sobel(_src, _dst, dx, dy, ksize, scale, delta, borderType)) - - CV_IPP_RUN(!(ocl::isOpenCLActivated() && _dst.isUMat()), ipp_Deriv(_src, _dst, dx, dy, ksize, scale, delta, borderType)); - int ktype = std::max(CV_32F, std::max(ddepth, sdepth)); Mat kx, ky; @@ -451,11 +436,30 @@ void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy, ky *= scale; } - CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2 && ksize == 3 && + CV_OCL_RUN(ocl::isOpenCLActivated() && _dst.isUMat() && _src.dims() <= 2 && ksize == 3 && (size_t)_src.rows() > ky.total() && (size_t)_src.cols() > kx.total(), ocl_sepFilter3x3_8UC1(_src, _dst, ddepth, kx, ky, delta, borderType)); - sepFilter2D( _src, _dst, ddepth, kx, ky, Point(-1, -1), delta, borderType ); + CV_OCL_RUN(ocl::isOpenCLActivated() && _dst.isUMat() && _src.dims() <= 2 && (size_t)_src.rows() > kx.total() && (size_t)_src.cols() > kx.total(), + ocl_sepFilter2D(_src, _dst, ddepth, 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(sobel, cv_hal_sobel, 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, dx, dy, ksize, scale, delta, borderType&~BORDER_ISOLATED); + + CV_OVX_RUN(true, + openvx_sobel(src, dst, dx, dy, ksize, scale, delta, borderType)) + + CV_IPP_RUN_FAST(ipp_Deriv(src, dst, dx, dy, ksize, scale, delta, borderType)); + + sepFilter2D(src, dst, ddepth, kx, ky, Point(-1, -1), delta, borderType ); } @@ -470,17 +474,6 @@ void cv::Scharr( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy, int dtype = CV_MAKETYPE(ddepth, cn); _dst.create( _src.size(), dtype ); -#ifdef HAVE_TEGRA_OPTIMIZATION - if (tegra::useTegra() && scale == 1.0 && delta == 0) - { - Mat src = _src.getMat(), dst = _dst.getMat(); - if (tegra::scharr(src, dst, dx, dy, borderType)) - return; - } -#endif - - CV_IPP_RUN(!(ocl::isOpenCLActivated() && _dst.isUMat()), ipp_Deriv(_src, _dst, dx, dy, 0, scale, delta, borderType)); - int ktype = std::max(CV_32F, std::max(ddepth, sdepth)); Mat kx, ky; @@ -495,11 +488,28 @@ void cv::Scharr( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy, ky *= scale; } - CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2 && + CV_OCL_RUN(ocl::isOpenCLActivated() && _dst.isUMat() && _src.dims() <= 2 && (size_t)_src.rows() > ky.total() && (size_t)_src.cols() > kx.total(), ocl_sepFilter3x3_8UC1(_src, _dst, ddepth, kx, ky, delta, borderType)); - sepFilter2D( _src, _dst, ddepth, kx, ky, Point(-1, -1), delta, borderType ); + CV_OCL_RUN(ocl::isOpenCLActivated() && _dst.isUMat() && _src.dims() <= 2 && + (size_t)_src.rows() > kx.total() && (size_t)_src.cols() > kx.total(), + ocl_sepFilter2D(_src, _dst, ddepth, 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(scharr, cv_hal_scharr, 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, dx, dy, scale, delta, borderType&~BORDER_ISOLATED); + + CV_IPP_RUN_FAST(ipp_Deriv(src, dst, dx, dy, 0, scale, delta, borderType)); + + sepFilter2D( src, dst, ddepth, kx, ky, Point(-1, -1), delta, borderType ); } #ifdef HAVE_OPENCL diff --git a/modules/imgproc/src/hal_replacement.hpp b/modules/imgproc/src/hal_replacement.hpp index d48090506f..0921a84940 100644 --- a/modules/imgproc/src/hal_replacement.hpp +++ b/modules/imgproc/src/hal_replacement.hpp @@ -701,6 +701,61 @@ inline int hal_ni_gaussianBlur(const uchar* src_data, size_t src_step, uchar* ds #define cv_hal_gaussianBlur hal_ni_gaussianBlur //! @endcond +/** + @brief Computes Sobel derivatives + @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 cn Number of channels + @param margin_left,margin_top,margin_right,margin_bottom Margins for source image + @param dx,dy orders of the derivative x and y respectively + @param ksize Size of kernel + @param scale Scale factor for the computed derivative values + @param delta Delta value that is added to the results prior to storing them in dst + @param border_type Border type +*/ +inline int hal_ni_sobel(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, int dx, int dy, int ksize, double scale, double delta, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } + +//! @cond IGNORED +#define cv_hal_sobel hal_ni_sobel +//! @endcond + +/** + @brief Computes Scharr 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 cn Number of channels + @param margin_left,margin_top,margin_right,margin_bottom Margins for source image + @param dx,dy orders of the derivative x and y respectively + @param scale Scale factor for the computed derivative values + @param delta Delta value that is added to the results prior to storing them in dst + @param border_type Border type +*/ +inline int hal_ni_scharr(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, int dx, int dy, double scale, double delta, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } + +//! @cond IGNORED +#define cv_hal_scharr hal_ni_scharr +//! @endcond + +/** + @brief Perform Gaussian Blur and downsampling for input tile. + @param depth Depths of source and destination image + @param src_data,src_step Source image + @param dst_data,dst_step Destination image + @param src_width,src_height Source image dimensions + @param dst_width,dst_height Destination image dimensions + @param cn Number of channels + @param border_type Border type +*/ +inline int hal_ni_pyrdown(const uchar* src_data, size_t src_step, int src_width, int src_height, uchar* dst_data, size_t dst_step, int dst_width, int dst_height, int depth, int cn, int border_type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } + +//! @cond IGNORED +#define cv_hal_pyrdown hal_ni_pyrdown +//! @endcond + //! @} #if defined __GNUC__ diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index 7f42f56240..7ece7f5537 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -1353,6 +1353,8 @@ void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borde Mat dst = _dst.getMat(); int depth = src.depth(); + CALL_HAL(pyrDown, cv_hal_pyrdown, src.data, src.step, src.cols, src.rows, dst.data, dst.step, dst.cols, dst.rows, depth, src.channels(), borderType); + #ifdef HAVE_TEGRA_OPTIMIZATION if(borderType == BORDER_DEFAULT && tegra::useTegra() && tegra::pyrDown(src, dst)) return;