Skip to content

Commit 6185f72

Browse files
ElenaGvozdevamshabunin
authored andcommitted
Merge pull request opencv#10172 from ElenaGvozdeva:eg/HAL_sobel
* add HAL for SobelFilter * add HAL for pyrDown * add HAL for Scharr
1 parent a2811d9 commit 6185f72

File tree

3 files changed

+98
-31
lines changed

3 files changed

+98
-31
lines changed

modules/imgproc/src/deriv.cpp

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "opencl_kernels_imgproc.hpp"
4545

4646
#include "opencv2/core/openvx/ovx_defs.hpp"
47+
#include "filter.hpp"
4748

4849
/****************************************************************************************\
4950
Sobel & Scharr Derivative Filters
@@ -421,22 +422,6 @@ void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy,
421422
int dtype = CV_MAKE_TYPE(ddepth, cn);
422423
_dst.create( _src.size(), dtype );
423424

424-
#ifdef HAVE_TEGRA_OPTIMIZATION
425-
if (tegra::useTegra() && scale == 1.0 && delta == 0)
426-
{
427-
Mat src = _src.getMat(), dst = _dst.getMat();
428-
if (ksize == 3 && tegra::sobel3x3(src, dst, dx, dy, borderType))
429-
return;
430-
if (ksize == -1 && tegra::scharr(src, dst, dx, dy, borderType))
431-
return;
432-
}
433-
#endif
434-
435-
CV_OVX_RUN(true,
436-
openvx_sobel(_src, _dst, dx, dy, ksize, scale, delta, borderType))
437-
438-
CV_IPP_RUN(!(ocl::isOpenCLActivated() && _dst.isUMat()), ipp_Deriv(_src, _dst, dx, dy, ksize, scale, delta, borderType));
439-
440425
int ktype = std::max(CV_32F, std::max(ddepth, sdepth));
441426

442427
Mat kx, ky;
@@ -451,11 +436,30 @@ void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy,
451436
ky *= scale;
452437
}
453438

454-
CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2 && ksize == 3 &&
439+
CV_OCL_RUN(ocl::isOpenCLActivated() && _dst.isUMat() && _src.dims() <= 2 && ksize == 3 &&
455440
(size_t)_src.rows() > ky.total() && (size_t)_src.cols() > kx.total(),
456441
ocl_sepFilter3x3_8UC1(_src, _dst, ddepth, kx, ky, delta, borderType));
457442

458-
sepFilter2D( _src, _dst, ddepth, kx, ky, Point(-1, -1), delta, borderType );
443+
CV_OCL_RUN(ocl::isOpenCLActivated() && _dst.isUMat() && _src.dims() <= 2 && (size_t)_src.rows() > kx.total() && (size_t)_src.cols() > kx.total(),
444+
ocl_sepFilter2D(_src, _dst, ddepth, kx, ky, Point(-1, -1), 0, borderType))
445+
446+
Mat src = _src.getMat();
447+
Mat dst = _dst.getMat();
448+
449+
Point ofs;
450+
Size wsz(src.cols, src.rows);
451+
if(!(borderType & BORDER_ISOLATED))
452+
src.locateROI( wsz, ofs );
453+
454+
CALL_HAL(sobel, cv_hal_sobel, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, ddepth, cn,
455+
ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, dx, dy, ksize, scale, delta, borderType&~BORDER_ISOLATED);
456+
457+
CV_OVX_RUN(true,
458+
openvx_sobel(src, dst, dx, dy, ksize, scale, delta, borderType))
459+
460+
CV_IPP_RUN_FAST(ipp_Deriv(src, dst, dx, dy, ksize, scale, delta, borderType));
461+
462+
sepFilter2D(src, dst, ddepth, kx, ky, Point(-1, -1), delta, borderType );
459463
}
460464

461465

@@ -470,17 +474,6 @@ void cv::Scharr( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy,
470474
int dtype = CV_MAKETYPE(ddepth, cn);
471475
_dst.create( _src.size(), dtype );
472476

473-
#ifdef HAVE_TEGRA_OPTIMIZATION
474-
if (tegra::useTegra() && scale == 1.0 && delta == 0)
475-
{
476-
Mat src = _src.getMat(), dst = _dst.getMat();
477-
if (tegra::scharr(src, dst, dx, dy, borderType))
478-
return;
479-
}
480-
#endif
481-
482-
CV_IPP_RUN(!(ocl::isOpenCLActivated() && _dst.isUMat()), ipp_Deriv(_src, _dst, dx, dy, 0, scale, delta, borderType));
483-
484477
int ktype = std::max(CV_32F, std::max(ddepth, sdepth));
485478

486479
Mat kx, ky;
@@ -495,11 +488,28 @@ void cv::Scharr( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy,
495488
ky *= scale;
496489
}
497490

498-
CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2 &&
491+
CV_OCL_RUN(ocl::isOpenCLActivated() && _dst.isUMat() && _src.dims() <= 2 &&
499492
(size_t)_src.rows() > ky.total() && (size_t)_src.cols() > kx.total(),
500493
ocl_sepFilter3x3_8UC1(_src, _dst, ddepth, kx, ky, delta, borderType));
501494

502-
sepFilter2D( _src, _dst, ddepth, kx, ky, Point(-1, -1), delta, borderType );
495+
CV_OCL_RUN(ocl::isOpenCLActivated() && _dst.isUMat() && _src.dims() <= 2 &&
496+
(size_t)_src.rows() > kx.total() && (size_t)_src.cols() > kx.total(),
497+
ocl_sepFilter2D(_src, _dst, ddepth, kx, ky, Point(-1, -1), 0, borderType))
498+
499+
Mat src = _src.getMat();
500+
Mat dst = _dst.getMat();
501+
502+
Point ofs;
503+
Size wsz(src.cols, src.rows);
504+
if(!(borderType & BORDER_ISOLATED))
505+
src.locateROI( wsz, ofs );
506+
507+
CALL_HAL(scharr, cv_hal_scharr, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, ddepth, cn,
508+
ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, dx, dy, scale, delta, borderType&~BORDER_ISOLATED);
509+
510+
CV_IPP_RUN_FAST(ipp_Deriv(src, dst, dx, dy, 0, scale, delta, borderType));
511+
512+
sepFilter2D( src, dst, ddepth, kx, ky, Point(-1, -1), delta, borderType );
503513
}
504514

505515
#ifdef HAVE_OPENCL

modules/imgproc/src/hal_replacement.hpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,61 @@ inline int hal_ni_gaussianBlur(const uchar* src_data, size_t src_step, uchar* ds
701701
#define cv_hal_gaussianBlur hal_ni_gaussianBlur
702702
//! @endcond
703703

704+
/**
705+
@brief Computes Sobel derivatives
706+
@param src_depth,dst_depth Depths of source and destination image
707+
@param src_data,src_step Source image
708+
@param dst_data,dst_step Destination image
709+
@param width,height Source image dimensions
710+
@param cn Number of channels
711+
@param margin_left,margin_top,margin_right,margin_bottom Margins for source image
712+
@param dx,dy orders of the derivative x and y respectively
713+
@param ksize Size of kernel
714+
@param scale Scale factor for the computed derivative values
715+
@param delta Delta value that is added to the results prior to storing them in dst
716+
@param border_type Border type
717+
*/
718+
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; }
719+
720+
//! @cond IGNORED
721+
#define cv_hal_sobel hal_ni_sobel
722+
//! @endcond
723+
724+
/**
725+
@brief Computes Scharr filter
726+
@param src_depth,dst_depth Depths of source and destination image
727+
@param src_data,src_step Source image
728+
@param dst_data,dst_step Destination image
729+
@param width,height Source image dimensions
730+
@param cn Number of channels
731+
@param margin_left,margin_top,margin_right,margin_bottom Margins for source image
732+
@param dx,dy orders of the derivative x and y respectively
733+
@param scale Scale factor for the computed derivative values
734+
@param delta Delta value that is added to the results prior to storing them in dst
735+
@param border_type Border type
736+
*/
737+
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; }
738+
739+
//! @cond IGNORED
740+
#define cv_hal_scharr hal_ni_scharr
741+
//! @endcond
742+
743+
/**
744+
@brief Perform Gaussian Blur and downsampling for input tile.
745+
@param depth Depths of source and destination image
746+
@param src_data,src_step Source image
747+
@param dst_data,dst_step Destination image
748+
@param src_width,src_height Source image dimensions
749+
@param dst_width,dst_height Destination image dimensions
750+
@param cn Number of channels
751+
@param border_type Border type
752+
*/
753+
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; }
754+
755+
//! @cond IGNORED
756+
#define cv_hal_pyrdown hal_ni_pyrdown
757+
//! @endcond
758+
704759
//! @}
705760

706761
#if defined __GNUC__

modules/imgproc/src/pyramids.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,8 @@ void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borde
13531353
Mat dst = _dst.getMat();
13541354
int depth = src.depth();
13551355

1356+
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);
1357+
13561358
#ifdef HAVE_TEGRA_OPTIMIZATION
13571359
if(borderType == BORDER_DEFAULT && tegra::useTegra() && tegra::pyrDown(src, dst))
13581360
return;

0 commit comments

Comments
 (0)