From a6ec12f58b88f8384ecebb87b60153ee4912e3c7 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov <2536374+asmorkalov@users.noreply.github.com> Date: Mon, 23 Sep 2024 08:44:22 +0300 Subject: [PATCH] Merge pull request #26163 from asmorkalov:as/HAL_schaar_deriv HAL interface for Sharr derivatives needed for Lukas-Kanade algorithm #26163 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- 3rdparty/carotene/hal/tegra_hal.hpp | 16 ++++++++++++++++ modules/video/src/hal_replacement.hpp | 21 +++++++++++++++++++++ modules/video/src/lkpyramid.cpp | 3 +++ 3 files changed, 40 insertions(+) diff --git a/3rdparty/carotene/hal/tegra_hal.hpp b/3rdparty/carotene/hal/tegra_hal.hpp index 31182a029a..2e07b7f526 100644 --- a/3rdparty/carotene/hal/tegra_hal.hpp +++ b/3rdparty/carotene/hal/tegra_hal.hpp @@ -1962,4 +1962,20 @@ inline int TEGRA_LKOpticalFlowLevel(const uchar *prev_data, size_t prev_data_ste #define cv_hal_LKOpticalFlowLevel TEGRA_LKOpticalFlowLevel #endif // __ARM_ARCH=7 +#if 0 // OpenCV provides fater parallel implementation +inline int TEGRA_ScharrDeriv(const uchar* src_data, size_t src_step, + short* dst_data, size_t dst_step, + int width, int height, int cn) +{ + if (!CAROTENE_NS::isSupportedConfiguration()) + return CV_HAL_ERROR_NOT_IMPLEMENTED; + + CAROTENE_NS::ScharrDeriv(CAROTENE_NS::Size2D(width, height), cn, src_data, src_step, dst_data, dst_step); + return CV_HAL_ERROR_OK; +} + +#undef cv_hal_ScharrDeriv +#define cv_hal_ScharrDeriv TEGRA_ScharrDeriv +#endif + #endif diff --git a/modules/video/src/hal_replacement.hpp b/modules/video/src/hal_replacement.hpp index 8d10ab39d1..b3551d1d3f 100644 --- a/modules/video/src/hal_replacement.hpp +++ b/modules/video/src/hal_replacement.hpp @@ -67,6 +67,27 @@ inline int hal_ni_LKOpticalFlowLevel(const uchar *prev_data, size_t prev_data_st #define cv_hal_LKOpticalFlowLevel hal_ni_LKOpticalFlowLevel //! @endcond +/** +@brief Computes Schaar derivatives with inteleaved layout xyxy... +@param src_data source image data +@param src_step source image step +@param dst_data destination buffer data +@param dst_step destination buffer step +@param width image width +@param height image height +@param cn source image channels +**/ +inline int hal_ni_ScharrDeriv(const uchar* src_data, size_t src_step, + short* dst_data, size_t dst_step, + int width, int height, int cn) +{ + return CV_HAL_ERROR_NOT_IMPLEMENTED; +} + +//! @cond IGNORED +#define cv_hal_ScharrDeriv hal_ni_ScharrDeriv +//! @endcond + //! @} #if defined(__clang__) diff --git a/modules/video/src/lkpyramid.cpp b/modules/video/src/lkpyramid.cpp index a9917595e9..1ed0482447 100644 --- a/modules/video/src/lkpyramid.cpp +++ b/modules/video/src/lkpyramid.cpp @@ -63,6 +63,9 @@ static void calcScharrDeriv(const cv::Mat& src, cv::Mat& dst) int rows = src.rows, cols = src.cols, cn = src.channels(), depth = src.depth(); CV_Assert(depth == CV_8U); dst.create(rows, cols, CV_MAKETYPE(DataType::depth, cn*2)); + + CALL_HAL(ScharrDeriv, cv_hal_ScharrDeriv, src.data, src.step, (short*)dst.data, dst.step, cols, rows, cn); + parallel_for_(Range(0, rows), cv::detail::ScharrDerivInvoker(src, dst), cv::getNumThreads()); }