From 12e2cc9502bc51bb01ed3fdd2f39ce1533c8236e Mon Sep 17 00:00:00 2001 From: Rostislav Vasilikhin Date: Sat, 27 Apr 2024 13:38:44 +0200 Subject: [PATCH] Merge pull request #25491 from savuor:rv/hal_norm_hamming HAL for Hamming norm added #25491 fixes #25474 ### 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 - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake --- modules/core/src/hal_replacement.hpp | 30 ++++++++++++++++++++++++++++ modules/core/src/norm.cpp | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/modules/core/src/hal_replacement.hpp b/modules/core/src/hal_replacement.hpp index 046b0678a4..15149453c7 100644 --- a/modules/core/src/hal_replacement.hpp +++ b/modules/core/src/hal_replacement.hpp @@ -214,6 +214,36 @@ inline int hal_ni_not8u(const uchar *src_data, size_t src_step, uchar *dst_data, #define cv_hal_not8u hal_ni_not8u //! @endcond +/** +Hamming norm of a vector +@param a pointer to vector data +@param n length of a vector +@param cellSize how many bits of the vector will be added and treated as a single bit, can be 1 (standard Hamming distance), 2 or 4 +@param result pointer to result output +*/ +//! @addtogroup core_hal_interface_hamming Hamming distance +//! @{ +inline int hal_ni_normHamming8u(const uchar* a, int n, int cellSize, int* result) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +//! @} + +/** +Hamming distance between two vectors +@param a pointer to first vector data +@param b pointer to second vector data +@param n length of vectors +@param cellSize how many bits of the vectors will be added and treated as a single bit, can be 1 (standard Hamming distance), 2 or 4 +@param result pointer to result output +*/ +//! @addtogroup core_hal_interface_hamming Hamming distance +//! @{ +inline int hal_ni_normHammingDiff8u(const uchar* a, const uchar* b, int n, int cellSize, int* result) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +//! @} + +//! @cond IGNORED +#define cv_hal_normHamming8u hal_ni_normHamming8u +#define cv_hal_normHammingDiff8u hal_ni_normHammingDiff8u +//! @endcond + /** Compare: _dst[i] = src1[i] op src2[i]_ @param src1_data first source image data diff --git a/modules/core/src/norm.cpp b/modules/core/src/norm.cpp index 49d781fcb0..f2f84c35b8 100644 --- a/modules/core/src/norm.cpp +++ b/modules/core/src/norm.cpp @@ -52,6 +52,9 @@ static const uchar popCountTable4[] = int normHamming(const uchar* a, int n, int cellSize) { + int output; + CALL_HAL_RET(normHamming8u, cv_hal_normHamming8u, output, a, n, cellSize); + if( cellSize == 1 ) return normHamming(a, n); const uchar* tab = 0; @@ -98,6 +101,9 @@ int normHamming(const uchar* a, int n, int cellSize) int normHamming(const uchar* a, const uchar* b, int n, int cellSize) { + int output; + CALL_HAL_RET(normHammingDiff8u, cv_hal_normHammingDiff8u, output, a, b, n, cellSize); + if( cellSize == 1 ) return normHamming(a, b, n); const uchar* tab = 0;