Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =========================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 0 additions & 12 deletions modules/core/include/opencv2/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions modules/core/include/opencv2/core/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions modules/core/src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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
};

Expand Down
2 changes: 1 addition & 1 deletion modules/imgproc/include/opencv2/imgproc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions modules/imgproc/src/smooth.dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 4 additions & 12 deletions modules/imgproc/test/test_smooth_bitexact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down