mirror of
https://github.com/opencv/opencv.git
synced 2024-11-27 12:40:05 +08:00
Post-merge fixes for algorithm hint API.
This commit is contained in:
parent
81f33103fd
commit
a6b8ea892b
@ -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 =========================
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -544,6 +544,18 @@ bool isAligned(const void* p1, const void* p2, const void* p3, const void* p4)
|
||||
return isAligned<N>(((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,
|
||||
|
@ -46,7 +46,6 @@
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/core/utils/configuration.private.hpp>
|
||||
#include <opencv2/core/utils/trace.private.hpp>
|
||||
|
||||
@ -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
|
||||
};
|
||||
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user