diff --git a/CMakeLists.txt b/CMakeLists.txt index c196d0f2be..e1dd4e5cd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1261,7 +1261,7 @@ endif() if(DEFINED OPENCV_ALGO_HINT_DEFAULT) status(" Algorithm Hint:" ${OPENCV_ALGO_HINT_DEFAULT}) else() - status(" Algorithm Hint:" " ALGO_ACCURATE") + status(" Algorithm Hint:" " ALGO_HINT_ACCURATE") endif() # ========================= CPU code generation mode ========================= diff --git a/doc/tutorials/introduction/config_reference/config_reference.markdown b/doc/tutorials/introduction/config_reference/config_reference.markdown index e43b8793e5..ef00ca5356 100644 --- a/doc/tutorials/introduction/config_reference/config_reference.markdown +++ b/doc/tutorials/introduction/config_reference/config_reference.markdown @@ -217,7 +217,7 @@ Following options can be used to produce special builds with instrumentation or | `ENABLE_BUILD_HARDENING` | GCC, Clang, MSVC | Enable compiler options which reduce possibility of code exploitation. | | `ENABLE_LTO` | GCC, Clang, MSVC | Enable Link Time Optimization (LTO). | | `ENABLE_THIN_LTO` | Clang | Enable thin LTO which incorporates intermediate bitcode to binaries allowing consumers optimize their applications later. | -| `OPENCV_ALGO_HINT_DEFAULT` | Any | Set default OpenCV implementation hint value: `ALGO_ACCURATE` or `ALGO_APROX`. Dangerous! The option changes behaviour globally and may affect accuracy of many algorithms. | +| `OPENCV_ALGO_HINT_DEFAULT` | Any | Set default OpenCV implementation hint value: `ALGO_HINT_ACCURATE` or `ALGO_HINT_APROX`. Dangerous! The option changes behaviour globally and may affect accuracy of many algorithms. | @see [GCC instrumentation](https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html) @see [Build hardening](https://en.wikipedia.org/wiki/Hardening_(computing)) diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index 4bfb95fede..b58a3a6ccb 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -150,18 +150,6 @@ It is possible to alternate error processing by using #redirectError(). */ CV_EXPORTS CV_NORETURN void error(const Exception& exc); -/*! @brief Flags that allow to midify some functions behavior. Used as set of flags. -*/ -enum AlgorithmHint { - ALGO_DEFAULT = 0, //!< Default algorithm behaviour defined during OpenCV build - ALGO_ACCURATE = 1, //!< Use generic portable implementation - ALGO_APPROX = 2, //!< Allow alternative approximations to get faster implementation. Behaviour and result depends on a platform -}; - -/*! @brief Returns ImplementationHint selected by default, a.k.a. `IMPL_DEFAULT` defined during OpenCV compilation. - */ -CV_EXPORTS_W AlgorithmHint getDefaultAlgorithmHint(); - enum SortFlags { SORT_EVERY_ROW = 0, //!< each matrix row is sorted independently SORT_EVERY_COLUMN = 1, //!< each matrix column is sorted //!< independently; this flag and the previous one are diff --git a/modules/core/include/opencv2/core/utility.hpp b/modules/core/include/opencv2/core/utility.hpp index e491352bcf..5eed688c83 100644 --- a/modules/core/include/opencv2/core/utility.hpp +++ b/modules/core/include/opencv2/core/utility.hpp @@ -544,6 +544,18 @@ bool isAligned(const void* p1, const void* p2, const void* p3, const void* p4) return isAligned(((size_t)p1)|((size_t)p2)|((size_t)p3)|((size_t)p4)); } +/*! @brief Flags that allow to midify some functions behavior. Used as set of flags. +*/ +enum AlgorithmHint { + ALGO_HINT_DEFAULT = 0, //!< Default algorithm behaviour defined during OpenCV build + ALGO_HINT_ACCURATE = 1, //!< Use generic portable implementation + ALGO_HINT_APPROX = 2, //!< Allow alternative approximations to get faster implementation. Behaviour and result depends on a platform +}; + +/*! @brief Returns AlgorithmHint defined during OpenCV compilation. Defines #ALGO_HINT_DEFAULT behavior. + */ +CV_EXPORTS_W AlgorithmHint getDefaultAlgorithmHint(); + /** @brief Enables or disables the optimized code. The function can be used to dynamically turn on and off optimized dispatched code (code that uses SSE4.2, AVX/AVX2, diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index eccef84c92..8d72d64f87 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -46,7 +46,6 @@ #include #include -#include #include #include @@ -2894,7 +2893,7 @@ AlgorithmHint getDefaultAlgorithmHint() #ifdef OPENCV_ALGO_HINT_DEFAULT return OPENCV_ALGO_HINT_DEFAULT; #else - return ALGO_ACCURATE; + return ALGO_HINT_ACCURATE; #endif }; diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 53ff5ea6bd..4456b3a88c 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -1543,7 +1543,7 @@ sigmaX, and sigmaY. CV_EXPORTS_W void GaussianBlur( InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY = 0, int borderType = BORDER_DEFAULT, - AlgorithmHint hint = cv::ALGO_DEFAULT ); + AlgorithmHint hint = cv::ALGO_HINT_DEFAULT ); /** @brief Applies the bilateral filter to an image. diff --git a/modules/imgproc/src/smooth.dispatch.cpp b/modules/imgproc/src/smooth.dispatch.cpp index 6bc989e520..f7dafbd956 100644 --- a/modules/imgproc/src/smooth.dispatch.cpp +++ b/modules/imgproc/src/smooth.dispatch.cpp @@ -612,7 +612,7 @@ void GaussianBlur(InputArray _src, OutputArray _dst, Size ksize, { CV_INSTRUMENT_REGION(); - if (hint == cv::ALGO_DEFAULT) + if (hint == cv::ALGO_HINT_DEFAULT) hint = cv::getDefaultAlgorithmHint(); CV_Assert(!_src.empty()); @@ -698,7 +698,7 @@ void GaussianBlur(InputArray _src, OutputArray _dst, Size ksize, borderType & ~BORDER_ISOLATED); } - if (hint == ALGO_APPROX) + if (hint == ALGO_HINT_APPROX) { Point ofs; Size wsz(src.cols, src.rows); @@ -768,7 +768,7 @@ void GaussianBlur(InputArray _src, OutputArray _dst, Size ksize, ofs.x, ofs.y, wsz.width - src2.cols - ofs.x, wsz.height - src2.rows - ofs.y, ksize.width, borderType&~BORDER_ISOLATED); } - if (hint == ALGO_APPROX) + if (hint == ALGO_HINT_APPROX) { Point ofs; Size wsz(src.cols, src.rows); diff --git a/modules/imgproc/test/test_smooth_bitexact.cpp b/modules/imgproc/test/test_smooth_bitexact.cpp index 2d1f7b5a4e..4546296877 100644 --- a/modules/imgproc/test/test_smooth_bitexact.cpp +++ b/modules/imgproc/test/test_smooth_bitexact.cpp @@ -288,21 +288,13 @@ TEST_P(GaussianBlurVsBitexact, approx) orig.convertTo(src, dtype); cv::Mat gt; - GaussianBlur(src, gt, Size(ksize, ksize), sigma, sigma, border, ALGO_ACCURATE); + GaussianBlur(src, gt, Size(ksize, ksize), sigma, sigma, border, ALGO_HINT_ACCURATE); cv::Mat dst; - GaussianBlur(src, dst, Size(ksize, ksize), sigma, sigma, border, ALGO_APPROX); + GaussianBlur(src, dst, Size(ksize, ksize), sigma, sigma, border, ALGO_HINT_APPROX); - cv::Mat diff; - cv::absdiff(dst, gt, diff); - cv::Mat flatten_diff = diff.reshape(1, diff.rows); - - int nz = countNonZero(flatten_diff); - EXPECT_LE(nz, 0.06*src.total()); // Less 6% of different pixels - - double min_val, max_val; - minMaxLoc(flatten_diff, &min_val, &max_val); - EXPECT_LE(max_val, 2); // expectes results floating +-1 + EXPECT_LE(cvtest::norm(dst, gt, NORM_INF), 1); + EXPECT_LE(cvtest::norm(dst, gt, NORM_L1 | NORM_RELATIVE), 0.06); // Less 6% of different pixels } INSTANTIATE_TEST_CASE_P(/*nothing*/, GaussianBlurVsBitexact,