From cb8cd478bcdc6c87e0fc7f4fbda43594b4984fd4 Mon Sep 17 00:00:00 2001 From: Michael Platings Date: Tue, 28 Jan 2025 14:56:32 +0000 Subject: [PATCH] Remove patch for Gaussian blur support in OpenCV Instead set cv::GaussianBlur's hint parameter to approximate. In addition, change build scripts to use the approximate hint by default. This is necessary to ensure that OpenCV's tests and benchmarks will use KleidiCV's Gaussian blur. --- adapters/opencv/opencv-4.11.patch | 30 ------------------------ conformity/opencv/test_gaussian_blur.cpp | 3 ++- scripts/benchmark/build.sh | 1 + scripts/ci-opencv.sh | 1 + scripts/run_opencv_conformity_checks.sh | 1 + 5 files changed, 5 insertions(+), 31 deletions(-) diff --git a/adapters/opencv/opencv-4.11.patch b/adapters/opencv/opencv-4.11.patch index 563f3deec..30962741c 100644 --- a/adapters/opencv/opencv-4.11.patch +++ b/adapters/opencv/opencv-4.11.patch @@ -185,36 +185,6 @@ index dfc718bf87..c1f953f230 100644 } interpolation &= ~WARP_RELATIVE_MAP; -diff --git a/modules/imgproc/src/smooth.dispatch.cpp b/modules/imgproc/src/smooth.dispatch.cpp -index f7dafbd956..13c1341716 100644 ---- a/modules/imgproc/src/smooth.dispatch.cpp -+++ b/modules/imgproc/src/smooth.dispatch.cpp -@@ -655,6 +655,25 @@ void GaussianBlur(InputArray _src, OutputArray _dst, Size ksize, - ocl_GaussianBlur_8UC1(_src, _dst, ksize, CV_MAT_DEPTH(type), kx, ky, 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 ); -+ -+ if (sigma1 == 0.0 && sigma2 == 0.0 && ksize.height == ksize.width) { -+ CALL_HAL(gaussianBlurBinomial, cv_hal_gaussianBlurBinomial, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, cn, -+ ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, borderType&~BORDER_ISOLATED); -+ } -+ -+ CALL_HAL(gaussianBlur, cv_hal_gaussianBlur, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, cn, -+ ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height, -+ sigma1, sigma2, borderType&~BORDER_ISOLATED); -+ } -+ - if(sdepth == CV_8U && ((borderType & BORDER_ISOLATED) || !_src.isSubmatrix())) - { - std::vector fkx, fky; diff --git a/modules/imgproc/test/test_imgwarp_strict.cpp b/modules/imgproc/test/test_imgwarp_strict.cpp index 673c6f03e6..56d9e0b554 100644 --- a/modules/imgproc/test/test_imgwarp_strict.cpp diff --git a/conformity/opencv/test_gaussian_blur.cpp b/conformity/opencv/test_gaussian_blur.cpp index 776fbec2b..d40bddd67 100644 --- a/conformity/opencv/test_gaussian_blur.cpp +++ b/conformity/opencv/test_gaussian_blur.cpp @@ -15,7 +15,8 @@ cv::Mat exec_gaussian_blur(cv::Mat& input) { cv::Mat input_mat = input.rowRange(0, input.rows - 2).clone(); cv::Size kernel(KernelSize, KernelSize); cv::Mat result; - cv::GaussianBlur(input_mat, result, kernel, sigma, sigma, BorderType); + cv::GaussianBlur(input_mat, result, kernel, sigma, sigma, BorderType, + cv::ALGO_HINT_APPROX); return result; } diff --git a/scripts/benchmark/build.sh b/scripts/benchmark/build.sh index c061f7480..237ad1374 100755 --- a/scripts/benchmark/build.sh +++ b/scripts/benchmark/build.sh @@ -42,6 +42,7 @@ KLEIDICV_SOURCE_PATH="$(realpath "${SCRIPT_PATH}/..")" export COMMON_CMAKE_ARGS="\ -DANDROID_ABI=arm64-v8a \ -DBUILD_PERF_TESTS=ON \ + -DOPENCV_ALGO_HINT_DEFAULT=ALGO_HINT_APPROX \ " # ------------------------------------------------------------------------------ diff --git a/scripts/ci-opencv.sh b/scripts/ci-opencv.sh index 248b393f0..8482cbc98 100755 --- a/scripts/ci-opencv.sh +++ b/scripts/ci-opencv.sh @@ -51,6 +51,7 @@ EXTRA_CMAKE_ARGS="\ -DWITH_ADE=OFF \ -DWITH_LAPACK=OFF \ -DOPENCV_PYTHON_SKIP_DETECTION=ON \ + -DOPENCV_ALGO_HINT_DEFAULT=ALGO_HINT_APPROX \ -DCMAKE_COMPILE_WARNING_AS_ERROR=ON \ -DCMAKE_CXX_FLAGS=-Wno-nontrivial-memcall" \ ./scripts/build-opencv.sh diff --git a/scripts/run_opencv_conformity_checks.sh b/scripts/run_opencv_conformity_checks.sh index ab7183d1d..6002ed2a7 100755 --- a/scripts/run_opencv_conformity_checks.sh +++ b/scripts/run_opencv_conformity_checks.sh @@ -59,6 +59,7 @@ common_cmake_args=( "-DWITH_ADE=OFF" "-DWITH_LAPACK=OFF" "-DOPENCV_PYTHON_SKIP_DETECTION=ON" + "-DOPENCV_ALGO_HINT_DEFAULT=ALGO_HINT_APPROX" ) if [[ -n "${OPENCV_VERSION}" ]]; then -- GitLab