From 7aaada4175f256183e64d8a24791be41ddfbe516 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 10 Feb 2025 15:26:41 +0300 Subject: [PATCH] Use HAL for cv::mean function too. --- modules/core/src/hal_replacement.hpp | 19 ++++++++----------- modules/core/src/mean.dispatch.cpp | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/modules/core/src/hal_replacement.hpp b/modules/core/src/hal_replacement.hpp index a0efad43ca..953de698e6 100644 --- a/modules/core/src/hal_replacement.hpp +++ b/modules/core/src/hal_replacement.hpp @@ -1104,26 +1104,23 @@ inline int hal_ni_transpose2d(const uchar* src_data, size_t src_step, uchar* dst #include "custom_hal.hpp" //! @cond IGNORED -#define CALL_HAL_RET(name, fun, retval, ...) \ + +#define CALL_HAL_RET2(name, fun, retval, ...) \ { \ - int res = __CV_EXPAND(fun(__VA_ARGS__, &retval)); \ + int res = __CV_EXPAND(fun(__VA_ARGS__)); \ if (res == CV_HAL_ERROR_OK) \ return retval; \ else if (res != CV_HAL_ERROR_NOT_IMPLEMENTED) \ CV_Error_(cv::Error::StsInternal, \ - ("HAL implementation " CVAUX_STR(name) " ==> " CVAUX_STR(fun) " returned %d (0x%08x)", res, res)); \ + ("HAL implementation " CVAUX_STR(name) " ==> " CVAUX_STR(fun) " returned %d (0x%08x)", res, res)); \ } +#define CALL_HAL_RET(name, fun, retval, ...) \ +CALL_HAL_RET2(name, fun, retval, __VA_ARGS__, &retval) #define CALL_HAL(name, fun, ...) \ -{ \ - int res = __CV_EXPAND(fun(__VA_ARGS__)); \ - if (res == CV_HAL_ERROR_OK) \ - return; \ - else if (res != CV_HAL_ERROR_NOT_IMPLEMENTED) \ - CV_Error_(cv::Error::StsInternal, \ - ("HAL implementation " CVAUX_STR(name) " ==> " CVAUX_STR(fun) " returned %d (0x%08x)", res, res)); \ -} +CALL_HAL_RET2(name, fun, ,__VA_ARGS__) + //! @endcond #endif diff --git a/modules/core/src/mean.dispatch.cpp b/modules/core/src/mean.dispatch.cpp index 619fae6f89..06860d74b4 100644 --- a/modules/core/src/mean.dispatch.cpp +++ b/modules/core/src/mean.dispatch.cpp @@ -130,13 +130,29 @@ Scalar mean(InputArray _src, InputArray _mask) CV_Assert( mask.empty() || mask.type() == CV_8U ); int k, cn = src.channels(), depth = src.depth(); - Scalar s; + Scalar s = Scalar::all(0.0); + + CV_Assert( cn <= 4 ); CV_IPP_RUN(IPP_VERSION_X100 >= 700, ipp_mean(src, mask, s), s) + if (src.isContinuous() && mask.isContinuous()) + { + CALL_HAL_RET2(meanStdDev, cv_hal_meanStdDev, s, src.data, 0, (int)src.total(), 1, src.type(), + &s[0], nullptr /*stddev*/, mask.data, 0); + } + else + { + if (src.dims <= 2) + { + CALL_HAL_RET2(meanStdDev, cv_hal_meanStdDev, s, src.data, src.step, src.cols, src.rows, src.type(), + &s[0], nullptr, mask.data, mask.step); + } + } + SumFunc func = getSumFunc(depth); - CV_Assert( cn <= 4 && func != 0 ); + CV_Assert( func != 0 ); const Mat* arrays[] = {&src, &mask, 0}; uchar* ptrs[2] = {};