mirror of
https://github.com/opencv/opencv.git
synced 2025-06-10 19:24:07 +08:00
Merge pull request #23736 from seanm:c++11-simplifications
Removed all pre-C++11 code, workarounds, and branches #23736 This removes a bunch of pre-C++11 workrarounds that are no longer necessary as C++11 is now required. It is a nice clean up and simplification. * No longer unconditionally #include <array> in cvdef.h, include explicitly where needed * Removed deprecated CV_NODISCARD, already unused in the codebase * Removed some pre-C++11 workarounds, and simplified some backwards compat defines * Removed CV_CXX_STD_ARRAY * Removed CV_CXX_MOVE_SEMANTICS and CV_CXX_MOVE * Removed all tests of CV_CXX11, now assume it's always true. This allowed removing a lot of dead code. * Updated some documentation consequently. * Removed all tests of CV_CXX11, now assume it's always true * Fixed links. --------- Co-authored-by: Maksim Shabunin <maksim.shabunin@gmail.com> Co-authored-by: Alexander Smorkalov <alexander.smorkalov@xperience.ai>
This commit is contained in:
parent
d066c44bce
commit
e64857c561
@ -9,6 +9,9 @@ How to use the OpenCV parallel_for_ to parallelize your code {#tutorial_how_to_u
|
|||||||
| -: | :- |
|
| -: | :- |
|
||||||
| Compatibility | OpenCV >= 3.0 |
|
| Compatibility | OpenCV >= 3.0 |
|
||||||
|
|
||||||
|
|
||||||
|
@note See also C++ lambda usage with parallel for in [tuturial](@ref tutorial_how_to_use_OpenCV_parallel_for_new).
|
||||||
|
|
||||||
Goal
|
Goal
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -20,7 +23,7 @@ If you want more information about multithreading, you will have to refer to a r
|
|||||||
to remain simple.
|
to remain simple.
|
||||||
|
|
||||||
Precondition
|
Precondition
|
||||||
----
|
------------
|
||||||
|
|
||||||
The first precondition is to have OpenCV built with a parallel framework.
|
The first precondition is to have OpenCV built with a parallel framework.
|
||||||
In OpenCV 3.2, the following parallel frameworks are available in that order:
|
In OpenCV 3.2, the following parallel frameworks are available in that order:
|
||||||
@ -50,7 +53,7 @@ We will use the example of drawing a Mandelbrot set to show how from a regular s
|
|||||||
the code to parallelize the computation.
|
the code to parallelize the computation.
|
||||||
|
|
||||||
Theory
|
Theory
|
||||||
-----------
|
------
|
||||||
|
|
||||||
The Mandelbrot set definition has been named in tribute to the mathematician Benoit Mandelbrot by the mathematician
|
The Mandelbrot set definition has been named in tribute to the mathematician Benoit Mandelbrot by the mathematician
|
||||||
Adrien Douady. It has been famous outside of the mathematics field as the image representation is an example of a
|
Adrien Douady. It has been famous outside of the mathematics field as the image representation is an example of a
|
||||||
@ -69,7 +72,7 @@ Here, we will just introduce the formula to draw the Mandelbrot set (from the me
|
|||||||
> \f[\limsup_{n\to\infty}|z_{n+1}|\leqslant2\f]
|
> \f[\limsup_{n\to\infty}|z_{n+1}|\leqslant2\f]
|
||||||
|
|
||||||
Pseudocode
|
Pseudocode
|
||||||
-----------
|
----------
|
||||||
|
|
||||||
A simple algorithm to generate a representation of the Mandelbrot set is called the
|
A simple algorithm to generate a representation of the Mandelbrot set is called the
|
||||||
["escape time algorithm"](https://en.wikipedia.org/wiki/Mandelbrot_set#Escape_time_algorithm).
|
["escape time algorithm"](https://en.wikipedia.org/wiki/Mandelbrot_set#Escape_time_algorithm).
|
||||||
@ -110,10 +113,10 @@ On this figure, we recall that the real part of a complex number is on the x-axi
|
|||||||
You can see that the whole shape can be repeatedly visible if we zoom at particular locations.
|
You can see that the whole shape can be repeatedly visible if we zoom at particular locations.
|
||||||
|
|
||||||
Implementation
|
Implementation
|
||||||
-----------
|
--------------
|
||||||
|
|
||||||
Escape time algorithm implementation
|
Escape time algorithm implementation
|
||||||
--------------------------
|
------------------------------------
|
||||||
|
|
||||||
@snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-escape-time-algorithm
|
@snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-escape-time-algorithm
|
||||||
|
|
||||||
@ -121,7 +124,7 @@ Here, we used the [`std::complex`](http://en.cppreference.com/w/cpp/numeric/comp
|
|||||||
complex number. This function performs the test to check if the pixel is in set or not and returns the "escaped" iteration.
|
complex number. This function performs the test to check if the pixel is in set or not and returns the "escaped" iteration.
|
||||||
|
|
||||||
Sequential Mandelbrot implementation
|
Sequential Mandelbrot implementation
|
||||||
--------------------------
|
------------------------------------
|
||||||
|
|
||||||
@snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-sequential
|
@snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-sequential
|
||||||
|
|
||||||
@ -149,7 +152,7 @@ The green curve corresponds to a simple linear scale transformation, the blue on
|
|||||||
and you can observe how the lowest values will be boosted when looking at the slope at these positions.
|
and you can observe how the lowest values will be boosted when looking at the slope at these positions.
|
||||||
|
|
||||||
Parallel Mandelbrot implementation
|
Parallel Mandelbrot implementation
|
||||||
--------------------------
|
----------------------------------
|
||||||
|
|
||||||
When looking at the sequential implementation, we can notice that each pixel is computed independently. To optimize the
|
When looking at the sequential implementation, we can notice that each pixel is computed independently. To optimize the
|
||||||
computation, we can perform multiple pixel calculations in parallel, by exploiting the multi-core architecture of modern
|
computation, we can perform multiple pixel calculations in parallel, by exploiting the multi-core architecture of modern
|
||||||
@ -181,7 +184,7 @@ C++ 11 standard allows to simplify the parallel implementation by get rid of the
|
|||||||
@snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-parallel-call-cxx11
|
@snippet how_to_use_OpenCV_parallel_for_.cpp mandelbrot-parallel-call-cxx11
|
||||||
|
|
||||||
Results
|
Results
|
||||||
-----------
|
-------
|
||||||
|
|
||||||
You can find the full tutorial code [here](https://github.com/opencv/opencv/blob/4.x/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.cpp).
|
You can find the full tutorial code [here](https://github.com/opencv/opencv/blob/4.x/samples/cpp/tutorial_code/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.cpp).
|
||||||
The performance of the parallel implementation depends of the type of CPU you have. For instance, on 4 cores / 8 threads
|
The performance of the parallel implementation depends of the type of CPU you have. For instance, on 4 cores / 8 threads
|
||||||
|
@ -7,10 +7,8 @@
|
|||||||
|
|
||||||
#include <opencv2/core/mat.hpp>
|
#include <opencv2/core/mat.hpp>
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
//#include <future>
|
//#include <future>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace cv {
|
namespace cv {
|
||||||
|
|
||||||
@ -69,7 +67,6 @@ public:
|
|||||||
|
|
||||||
CV_WRAP bool valid() const CV_NOEXCEPT;
|
CV_WRAP bool valid() const CV_NOEXCEPT;
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
inline AsyncArray(AsyncArray&& o) { p = o.p; o.p = NULL; }
|
inline AsyncArray(AsyncArray&& o) { p = o.p; o.p = NULL; }
|
||||||
inline AsyncArray& operator=(AsyncArray&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; }
|
inline AsyncArray& operator=(AsyncArray&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; }
|
||||||
|
|
||||||
@ -89,7 +86,6 @@ public:
|
|||||||
std::future<Mat> getFutureMat() const;
|
std::future<Mat> getFutureMat() const;
|
||||||
std::future<UMat> getFutureUMat() const;
|
std::future<UMat> getFutureUMat() const;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// PImpl
|
// PImpl
|
||||||
|
@ -752,89 +752,44 @@ __CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************************\
|
|
||||||
* CV_NODISCARD attribute (deprecated, GCC only) *
|
|
||||||
* DONT USE: use instead the standard CV_NODISCARD_STD macro above *
|
|
||||||
* this legacy method silently fails to issue warning until some version *
|
|
||||||
* after gcc 6.3.0. Yet with gcc 7+ you can use the above standard method *
|
|
||||||
* which makes this method useless. Don't use it. *
|
|
||||||
* @deprecated use instead CV_NODISCARD_STD *
|
|
||||||
\****************************************************************************************/
|
|
||||||
#ifndef CV_NODISCARD
|
|
||||||
# if defined(__GNUC__)
|
|
||||||
# define CV_NODISCARD __attribute__((__warn_unused_result__))
|
|
||||||
# elif defined(__clang__) && defined(__has_attribute)
|
|
||||||
# if __has_attribute(__warn_unused_result__)
|
|
||||||
# define CV_NODISCARD __attribute__((__warn_unused_result__))
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#ifndef CV_NODISCARD
|
|
||||||
# define CV_NODISCARD /* nothing by default */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************************\
|
/****************************************************************************************\
|
||||||
* C++ 11 *
|
* C++ 11 *
|
||||||
\****************************************************************************************/
|
\****************************************************************************************/
|
||||||
#ifndef CV_CXX11
|
#ifdef __cplusplus
|
||||||
# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
|
// MSVC was stuck at __cplusplus == 199711L for a long time, even where it supports C++11,
|
||||||
# define CV_CXX11 1
|
// so check _MSC_VER instead. See:
|
||||||
# endif
|
// <https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus>
|
||||||
#else
|
# if defined(_MSC_VER)
|
||||||
# if CV_CXX11 == 0
|
# if _MSC_VER < 1800
|
||||||
# undef CV_CXX11
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#ifndef CV_CXX11
|
|
||||||
# error "OpenCV 4.x+ requires enabled C++11 support"
|
# error "OpenCV 4.x+ requires enabled C++11 support"
|
||||||
# endif
|
# endif
|
||||||
|
# elif __cplusplus < 201103L
|
||||||
|
# error "OpenCV 4.x+ requires enabled C++11 support"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CV_CXX11
|
||||||
|
# define CV_CXX11 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CV_CXX_MOVE_SEMANTICS 1
|
|
||||||
#define CV_CXX_MOVE(x) std::move(x)
|
|
||||||
#define CV_CXX_STD_ARRAY 1
|
|
||||||
#include <array>
|
|
||||||
#ifndef CV_OVERRIDE
|
#ifndef CV_OVERRIDE
|
||||||
# define CV_OVERRIDE override
|
# define CV_OVERRIDE override
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CV_FINAL
|
#ifndef CV_FINAL
|
||||||
# define CV_FINAL final
|
# define CV_FINAL final
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CV_NOEXCEPT
|
#ifndef CV_NOEXCEPT
|
||||||
# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/)
|
|
||||||
# define CV_NOEXCEPT noexcept
|
# define CV_NOEXCEPT noexcept
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
#ifndef CV_NOEXCEPT
|
|
||||||
# define CV_NOEXCEPT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CV_CONSTEXPR
|
#ifndef CV_CONSTEXPR
|
||||||
# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/)
|
|
||||||
# define CV_CONSTEXPR constexpr
|
# define CV_CONSTEXPR constexpr
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
#ifndef CV_CONSTEXPR
|
|
||||||
# define CV_CONSTEXPR
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Integer types portability
|
// Integer types portability
|
||||||
#ifdef OPENCV_STDINT_HEADER
|
#ifdef __cplusplus
|
||||||
#include OPENCV_STDINT_HEADER
|
|
||||||
#elif defined(__cplusplus)
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1600 /* MSVS 2010 */
|
|
||||||
namespace cv {
|
|
||||||
typedef signed char int8_t;
|
|
||||||
typedef unsigned char uint8_t;
|
|
||||||
typedef signed short int16_t;
|
|
||||||
typedef unsigned short uint16_t;
|
|
||||||
typedef signed int int32_t;
|
|
||||||
typedef unsigned int uint32_t;
|
|
||||||
typedef signed __int64 int64_t;
|
|
||||||
typedef unsigned __int64 uint64_t;
|
|
||||||
}
|
|
||||||
#elif defined(_MSC_VER) || __cplusplus >= 201103L
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
namespace cv {
|
namespace cv {
|
||||||
using std::int8_t;
|
using std::int8_t;
|
||||||
@ -846,19 +801,6 @@ using std::uint32_t;
|
|||||||
using std::int64_t;
|
using std::int64_t;
|
||||||
using std::uint64_t;
|
using std::uint64_t;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#include <stdint.h>
|
|
||||||
namespace cv {
|
|
||||||
typedef ::int8_t int8_t;
|
|
||||||
typedef ::uint8_t uint8_t;
|
|
||||||
typedef ::int16_t int16_t;
|
|
||||||
typedef ::uint16_t uint16_t;
|
|
||||||
typedef ::int32_t int32_t;
|
|
||||||
typedef ::uint32_t uint32_t;
|
|
||||||
typedef ::int64_t int64_t;
|
|
||||||
typedef ::uint64_t uint64_t;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#else // pure C
|
#else // pure C
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -52,10 +52,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setException(const cv::Exception& exception);
|
void setException(const cv::Exception& exception);
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
explicit AsyncPromise(AsyncPromise&& o) { p = o.p; o.p = NULL; }
|
explicit AsyncPromise(AsyncPromise&& o) { p = o.p; o.p = NULL; }
|
||||||
AsyncPromise& operator=(AsyncPromise&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; }
|
AsyncPromise& operator=(AsyncPromise&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; }
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// PImpl
|
// PImpl
|
||||||
|
@ -8,14 +8,8 @@
|
|||||||
#ifndef CV__EXCEPTION_PTR
|
#ifndef CV__EXCEPTION_PTR
|
||||||
# if defined(__ANDROID__) && defined(ATOMIC_INT_LOCK_FREE) && ATOMIC_INT_LOCK_FREE < 2
|
# if defined(__ANDROID__) && defined(ATOMIC_INT_LOCK_FREE) && ATOMIC_INT_LOCK_FREE < 2
|
||||||
# define CV__EXCEPTION_PTR 0 // Not supported, details: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58938
|
# define CV__EXCEPTION_PTR 0 // Not supported, details: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58938
|
||||||
# elif defined(CV_CXX11)
|
# else
|
||||||
# define CV__EXCEPTION_PTR 1
|
# define CV__EXCEPTION_PTR 1
|
||||||
# elif defined(_MSC_VER)
|
|
||||||
# define CV__EXCEPTION_PTR (_MSC_VER >= 1600)
|
|
||||||
# elif defined(__clang__)
|
|
||||||
# define CV__EXCEPTION_PTR 0 // C++11 only (see above)
|
|
||||||
# elif defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__)
|
|
||||||
# define CV__EXCEPTION_PTR (__GXX_EXPERIMENTAL_CXX0X__ > 0)
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#ifndef CV__EXCEPTION_PTR
|
#ifndef CV__EXCEPTION_PTR
|
||||||
|
@ -61,8 +61,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(OPENCV_DISABLE_EIGEN_TENSOR_SUPPORT)
|
#if !defined(OPENCV_DISABLE_EIGEN_TENSOR_SUPPORT)
|
||||||
#if EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3 \
|
#if EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3
|
||||||
&& defined(CV_CXX11) && defined(CV_CXX_STD_ARRAY)
|
|
||||||
#include <unsupported/Eigen/CXX11/Tensor>
|
#include <unsupported/Eigen/CXX11/Tensor>
|
||||||
#define OPENCV_EIGEN_TENSOR_SUPPORT 1
|
#define OPENCV_EIGEN_TENSOR_SUPPORT 1
|
||||||
#endif // EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3
|
#endif // EIGEN_WORLD_VERSION == 3 && EIGEN_MAJOR_VERSION >= 3
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
|
|
||||||
#include "opencv2/core/bufferpool.hpp"
|
#include "opencv2/core/bufferpool.hpp"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace cv
|
namespace cv
|
||||||
|
@ -376,10 +376,8 @@ public:
|
|||||||
static Vec randn(_Tp a, _Tp b);
|
static Vec randn(_Tp a, _Tp b);
|
||||||
static Vec randu(_Tp a, _Tp b);
|
static Vec randu(_Tp a, _Tp b);
|
||||||
static Vec zeros();
|
static Vec zeros();
|
||||||
#ifdef CV_CXX11
|
|
||||||
static Vec diag(_Tp alpha) = delete;
|
static Vec diag(_Tp alpha) = delete;
|
||||||
static Vec eye() = delete;
|
static Vec eye() = delete;
|
||||||
#endif
|
|
||||||
|
|
||||||
//! per-element multiplication
|
//! per-element multiplication
|
||||||
Vec mul(const Vec<_Tp, cn>& v) const;
|
Vec mul(const Vec<_Tp, cn>& v) const;
|
||||||
@ -402,9 +400,7 @@ public:
|
|||||||
const _Tp& operator ()(int i) const;
|
const _Tp& operator ()(int i) const;
|
||||||
_Tp& operator ()(int i);
|
_Tp& operator ()(int i);
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
Vec<_Tp, cn>& operator=(const Vec<_Tp, cn>& rhs) = default;
|
Vec<_Tp, cn>& operator=(const Vec<_Tp, cn>& rhs) = default;
|
||||||
#endif
|
|
||||||
|
|
||||||
Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp);
|
Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp);
|
||||||
Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp);
|
Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp);
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
|
|
||||||
//#define OPENCV_DISABLE_ALLOCATOR_STATS
|
//#define OPENCV_DISABLE_ALLOCATOR_STATS
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
#ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
|
#ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
|
||||||
@ -26,14 +24,6 @@
|
|||||||
#define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE long long
|
#define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE long long
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else // CV_CXX11
|
|
||||||
|
|
||||||
#ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
|
|
||||||
#define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE int // CV_XADD supports int only
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // CV_CXX11
|
|
||||||
|
|
||||||
namespace cv { namespace utils {
|
namespace cv { namespace utils {
|
||||||
|
|
||||||
#ifdef CV__ALLOCATOR_STATS_LOG
|
#ifdef CV__ALLOCATOR_STATS_LOG
|
||||||
@ -59,7 +49,7 @@ public:
|
|||||||
void onAllocate(size_t /*sz*/) {}
|
void onAllocate(size_t /*sz*/) {}
|
||||||
void onFree(size_t /*sz*/) {}
|
void onFree(size_t /*sz*/) {}
|
||||||
|
|
||||||
#elif defined(CV_CXX11)
|
#else
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE counter_t;
|
typedef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE counter_t;
|
||||||
@ -104,49 +94,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
curr -= (counter_t)sz;
|
curr -= (counter_t)sz;
|
||||||
}
|
}
|
||||||
|
#endif // OPENCV_DISABLE_ALLOCATOR_STATS
|
||||||
#else // non C++11
|
|
||||||
|
|
||||||
protected:
|
|
||||||
typedef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE counter_t;
|
|
||||||
volatile counter_t curr, total, total_allocs, peak; // overflow is possible, CV_XADD operates with 'int' only
|
|
||||||
public:
|
|
||||||
AllocatorStatistics()
|
|
||||||
: curr(0), total(0), total_allocs(0), peak(0)
|
|
||||||
{}
|
|
||||||
~AllocatorStatistics() CV_OVERRIDE {}
|
|
||||||
|
|
||||||
uint64_t getCurrentUsage() const CV_OVERRIDE { return (uint64_t)curr; }
|
|
||||||
uint64_t getTotalUsage() const CV_OVERRIDE { return (uint64_t)total; }
|
|
||||||
uint64_t getNumberOfAllocations() const CV_OVERRIDE { return (uint64_t)total_allocs; }
|
|
||||||
uint64_t getPeakUsage() const CV_OVERRIDE { return (uint64_t)peak; }
|
|
||||||
|
|
||||||
void resetPeakUsage() CV_OVERRIDE { peak = curr; }
|
|
||||||
|
|
||||||
// Controller interface
|
|
||||||
void onAllocate(size_t sz)
|
|
||||||
{
|
|
||||||
#ifdef CV__ALLOCATOR_STATS_LOG
|
|
||||||
CV__ALLOCATOR_STATS_LOG(cv::format("allocate: %lld (curr=%lld)", (long long int)sz, (long long int)curr));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
counter_t new_curr = (counter_t)CV_XADD(&curr, (counter_t)sz) + (counter_t)sz;
|
|
||||||
|
|
||||||
peak = std::max((counter_t)peak, new_curr); // non-thread safe
|
|
||||||
|
|
||||||
//CV_XADD(&total, (uint64_t)sz); // overflow with int, non-reliable...
|
|
||||||
total += sz;
|
|
||||||
|
|
||||||
CV_XADD(&total_allocs, (counter_t)1);
|
|
||||||
}
|
|
||||||
void onFree(size_t sz)
|
|
||||||
{
|
|
||||||
#ifdef CV__ALLOCATOR_STATS_LOG
|
|
||||||
CV__ALLOCATOR_STATS_LOG(cv::format("free: %lld (curr=%lld)", (long long int)sz, (long long int)curr));
|
|
||||||
#endif
|
|
||||||
CV_XADD(&curr, (counter_t)-sz);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CV__ALLOCATOR_STATS_LOG
|
#ifdef CV__ALLOCATOR_STATS_LOG
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// of this distribution and at http://opencv.org/license.html.
|
// of this distribution and at http://opencv.org/license.html.
|
||||||
|
|
||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
//#undef CV_CXX11 // debug non C++11 mode
|
|
||||||
#include "opencv2/core/async.hpp"
|
#include "opencv2/core/async.hpp"
|
||||||
#include "opencv2/core/detail/async_promise.hpp"
|
#include "opencv2/core/detail/async_promise.hpp"
|
||||||
|
|
||||||
@ -16,11 +15,9 @@
|
|||||||
|
|
||||||
#ifndef OPENCV_DISABLE_THREAD_SUPPORT
|
#ifndef OPENCV_DISABLE_THREAD_SUPPORT
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace cv {
|
namespace cv {
|
||||||
|
|
||||||
@ -37,12 +34,8 @@ struct AsyncArray::Impl
|
|||||||
void releasePromise() CV_NOEXCEPT { CV_XADD(&refcount_promise, -1); if(1 == CV_XADD(&refcount, -1)) delete this; } \
|
void releasePromise() CV_NOEXCEPT { CV_XADD(&refcount_promise, -1); if(1 == CV_XADD(&refcount, -1)) delete this; } \
|
||||||
int refcount_promise;
|
int refcount_promise;
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
mutable std::mutex mtx;
|
mutable std::mutex mtx;
|
||||||
mutable std::condition_variable cond_var;
|
mutable std::condition_variable cond_var;
|
||||||
#else
|
|
||||||
mutable cv::Mutex mtx;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mutable bool has_result; // Mat, UMat or exception
|
mutable bool has_result; // Mat, UMat or exception
|
||||||
|
|
||||||
@ -88,11 +81,7 @@ struct AsyncArray::Impl
|
|||||||
if (!wait_for(timeoutNs))
|
if (!wait_for(timeoutNs))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#ifdef CV_CXX11
|
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
#else
|
|
||||||
cv::AutoLock lock(mtx);
|
|
||||||
#endif
|
|
||||||
if (has_result)
|
if (has_result)
|
||||||
{
|
{
|
||||||
if (!result_mat.empty())
|
if (!result_mat.empty())
|
||||||
@ -145,7 +134,6 @@ struct AsyncArray::Impl
|
|||||||
if (timeoutNs == 0)
|
if (timeoutNs == 0)
|
||||||
return has_result;
|
return has_result;
|
||||||
CV_LOG_INFO(NULL, "Waiting for async result ...");
|
CV_LOG_INFO(NULL, "Waiting for async result ...");
|
||||||
#ifdef CV_CXX11
|
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
const auto cond_pred = [&]{ return has_result == true; };
|
const auto cond_pred = [&]{ return has_result == true; };
|
||||||
if (timeoutNs > 0)
|
if (timeoutNs > 0)
|
||||||
@ -156,9 +144,6 @@ struct AsyncArray::Impl
|
|||||||
CV_Assert(has_result);
|
CV_Assert(has_result);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
CV_Error(Error::StsNotImplemented, "OpenCV has been built without async waiting support (C++11 is required)");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncArray getArrayResult()
|
AsyncArray getArrayResult()
|
||||||
@ -175,11 +160,7 @@ struct AsyncArray::Impl
|
|||||||
{
|
{
|
||||||
if (future_is_returned && refcount_future == 0)
|
if (future_is_returned && refcount_future == 0)
|
||||||
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
||||||
#ifdef CV_CXX11
|
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
#else
|
|
||||||
cv::AutoLock lock(mtx);
|
|
||||||
#endif
|
|
||||||
CV_Assert(!has_result);
|
CV_Assert(!has_result);
|
||||||
int k = value.kind();
|
int k = value.kind();
|
||||||
if (k == _InputArray::UMAT)
|
if (k == _InputArray::UMAT)
|
||||||
@ -193,9 +174,7 @@ struct AsyncArray::Impl
|
|||||||
value.copyTo(*result_mat.get());
|
value.copyTo(*result_mat.get());
|
||||||
}
|
}
|
||||||
has_result = true;
|
has_result = true;
|
||||||
#ifdef CV_CXX11
|
|
||||||
cond_var.notify_all();
|
cond_var.notify_all();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CV__EXCEPTION_PTR
|
#if CV__EXCEPTION_PTR
|
||||||
@ -203,18 +182,12 @@ struct AsyncArray::Impl
|
|||||||
{
|
{
|
||||||
if (future_is_returned && refcount_future == 0)
|
if (future_is_returned && refcount_future == 0)
|
||||||
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
||||||
#ifdef CV_CXX11
|
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
#else
|
|
||||||
cv::AutoLock lock(mtx);
|
|
||||||
#endif
|
|
||||||
CV_Assert(!has_result);
|
CV_Assert(!has_result);
|
||||||
has_exception = true;
|
has_exception = true;
|
||||||
exception = e;
|
exception = e;
|
||||||
has_result = true;
|
has_result = true;
|
||||||
#ifdef CV_CXX11
|
|
||||||
cond_var.notify_all();
|
cond_var.notify_all();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -222,18 +195,12 @@ struct AsyncArray::Impl
|
|||||||
{
|
{
|
||||||
if (future_is_returned && refcount_future == 0)
|
if (future_is_returned && refcount_future == 0)
|
||||||
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
||||||
#ifdef CV_CXX11
|
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
#else
|
|
||||||
cv::AutoLock lock(mtx);
|
|
||||||
#endif
|
|
||||||
CV_Assert(!has_result);
|
CV_Assert(!has_result);
|
||||||
has_exception = true;
|
has_exception = true;
|
||||||
cv_exception = e;
|
cv_exception = e;
|
||||||
has_result = true;
|
has_result = true;
|
||||||
#ifdef CV_CXX11
|
|
||||||
cond_var.notify_all();
|
cond_var.notify_all();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1919,12 +1919,7 @@ void _OutputArray::move(UMat& u) const
|
|||||||
int k = kind();
|
int k = kind();
|
||||||
if (k == UMAT)
|
if (k == UMAT)
|
||||||
{
|
{
|
||||||
#ifdef CV_CXX11
|
|
||||||
*(UMat*)obj = std::move(u);
|
*(UMat*)obj = std::move(u);
|
||||||
#else
|
|
||||||
*(UMat*)obj = u;
|
|
||||||
u.release();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (k == MAT)
|
else if (k == MAT)
|
||||||
{
|
{
|
||||||
@ -1959,12 +1954,7 @@ void _OutputArray::move(Mat& m) const
|
|||||||
}
|
}
|
||||||
else if (k == MAT)
|
else if (k == MAT)
|
||||||
{
|
{
|
||||||
#ifdef CV_CXX11
|
|
||||||
*(Mat*)obj = std::move(m);
|
*(Mat*)obj = std::move(m);
|
||||||
#else
|
|
||||||
*(Mat*)obj = m;
|
|
||||||
m.release();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (k == MATX)
|
else if (k == MATX)
|
||||||
{
|
{
|
||||||
|
@ -912,8 +912,7 @@ int getNumberOfCPUs_()
|
|||||||
* the minimum most value as it has high probablity of being right and safe.
|
* the minimum most value as it has high probablity of being right and safe.
|
||||||
* Return 1 if we get 0 or not found on all methods.
|
* Return 1 if we get 0 or not found on all methods.
|
||||||
*/
|
*/
|
||||||
#if defined CV_CXX11 \
|
#if !defined(__MINGW32__) /* not implemented (2020-03) */
|
||||||
&& !defined(__MINGW32__) /* not implemented (2020-03) */ \
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for this standard C++11 way, we do not return directly because
|
* Check for this standard C++11 way, we do not return directly because
|
||||||
|
@ -305,9 +305,7 @@ DECLARE_CV_CPUID_X86
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined CV_CXX11
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace cv
|
namespace cv
|
||||||
{
|
{
|
||||||
@ -909,50 +907,15 @@ bool useOptimized(void)
|
|||||||
|
|
||||||
int64 getTickCount(void)
|
int64 getTickCount(void)
|
||||||
{
|
{
|
||||||
#if defined CV_CXX11
|
|
||||||
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||||
return (int64)now.time_since_epoch().count();
|
return (int64)now.time_since_epoch().count();
|
||||||
#elif defined _WIN32 || defined WINCE
|
|
||||||
LARGE_INTEGER counter;
|
|
||||||
QueryPerformanceCounter( &counter );
|
|
||||||
return (int64)counter.QuadPart;
|
|
||||||
#elif defined __MACH__ && defined __APPLE__
|
|
||||||
return (int64)mach_absolute_time();
|
|
||||||
#elif defined __unix__
|
|
||||||
struct timespec tp;
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
|
||||||
return (int64)tp.tv_sec*1000000000 + tp.tv_nsec;
|
|
||||||
#else
|
|
||||||
struct timeval tv;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
return (int64)tv.tv_sec*1000000 + tv.tv_usec;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double getTickFrequency(void)
|
double getTickFrequency(void)
|
||||||
{
|
{
|
||||||
#if defined CV_CXX11
|
|
||||||
using clock_period_t = std::chrono::steady_clock::duration::period;
|
using clock_period_t = std::chrono::steady_clock::duration::period;
|
||||||
double clock_freq = clock_period_t::den / clock_period_t::num;
|
double clock_freq = clock_period_t::den / clock_period_t::num;
|
||||||
return clock_freq;
|
return clock_freq;
|
||||||
#elif defined _WIN32 || defined WINCE
|
|
||||||
LARGE_INTEGER freq;
|
|
||||||
QueryPerformanceFrequency(&freq);
|
|
||||||
return (double)freq.QuadPart;
|
|
||||||
#elif defined __MACH__ && defined __APPLE__
|
|
||||||
static double freq = 0;
|
|
||||||
if( freq == 0 )
|
|
||||||
{
|
|
||||||
mach_timebase_info_data_t sTimebaseInfo;
|
|
||||||
mach_timebase_info(&sTimebaseInfo);
|
|
||||||
freq = sTimebaseInfo.denom*1e9/sTimebaseInfo.numer;
|
|
||||||
}
|
|
||||||
return freq;
|
|
||||||
#elif defined __unix__
|
|
||||||
return 1e9;
|
|
||||||
#else
|
|
||||||
return 1e6;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined __GNUC__ && (defined __i386__ || defined __x86_64__ || defined __ppc__)
|
#if defined __GNUC__ && (defined __i386__ || defined __x86_64__ || defined __ppc__)
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include <opencv2/core/bindings_utils.hpp>
|
#include <opencv2/core/bindings_utils.hpp>
|
||||||
|
|
||||||
#if defined(CV_CXX11) && !defined(OPENCV_DISABLE_THREAD_SUPPORT)
|
#if !defined(OPENCV_DISABLE_THREAD_SUPPORT)
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#endif
|
#endif
|
||||||
@ -85,7 +85,7 @@ TEST(Core_Async, LikePythonTest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(CV_CXX11) && !defined(OPENCV_DISABLE_THREAD_SUPPORT)
|
#if !defined(OPENCV_DISABLE_THREAD_SUPPORT)
|
||||||
|
|
||||||
TEST(Core_Async, AsyncThread_Simple)
|
TEST(Core_Async, AsyncThread_Simple)
|
||||||
{
|
{
|
||||||
|
@ -8,10 +8,8 @@
|
|||||||
|
|
||||||
#include <opencv2/core/utils/fp_control_utils.hpp>
|
#include <opencv2/core/utils/fp_control_utils.hpp>
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace opencv_test { namespace {
|
namespace opencv_test { namespace {
|
||||||
|
|
||||||
@ -282,9 +280,7 @@ public:
|
|||||||
// FP state is not supported
|
// FP state is not supported
|
||||||
// no checks
|
// no checks
|
||||||
}
|
}
|
||||||
#ifdef CV_CXX11
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::details::FPDenormalsModeState base_state;
|
cv::details::FPDenormalsModeState base_state;
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
||||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include "opencv2/ts.hpp"
|
#include "opencv2/ts.hpp"
|
||||||
#include "opencv2/ts/ocl_test.hpp"
|
#include "opencv2/ts/ocl_test.hpp"
|
||||||
#include "opencv2/core/private.hpp"
|
#include "opencv2/core/private.hpp"
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
|
|
||||||
// This is .hpp file included from test_utils.cpp
|
// This is .hpp file included from test_utils.cpp
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
#include <thread> // std::thread
|
#include <thread> // std::thread
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "opencv2/core/utils/tls.hpp"
|
#include "opencv2/core/utils/tls.hpp"
|
||||||
|
|
||||||
@ -34,8 +32,6 @@ public:
|
|||||||
int TLSReporter::g_last_id = 0;
|
int TLSReporter::g_last_id = 0;
|
||||||
int TLSReporter::g_allocated = 0;
|
int TLSReporter::g_allocated = 0;
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static void callNThreadsWithTLS(int N, TLSData<T>& tls)
|
static void callNThreadsWithTLS(int N, TLSData<T>& tls)
|
||||||
{
|
{
|
||||||
@ -129,6 +125,4 @@ static void testTLSAccumulator(bool detachFirst)
|
|||||||
TEST(Core_TLS, AccumulatorHoldData_detachData) { testTLSAccumulator(true); }
|
TEST(Core_TLS, AccumulatorHoldData_detachData) { testTLSAccumulator(true); }
|
||||||
TEST(Core_TLS, AccumulatorHoldData_gather) { testTLSAccumulator(false); }
|
TEST(Core_TLS, AccumulatorHoldData_gather) { testTLSAccumulator(false); }
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}} // namespace
|
}} // namespace
|
||||||
|
@ -918,7 +918,6 @@ AsyncArray Net::Impl::forwardAsync(const String& outputName)
|
|||||||
CV_Assert(!empty());
|
CV_Assert(!empty());
|
||||||
FPDenormalsIgnoreHintScope fp_denormals_ignore_scope;
|
FPDenormalsIgnoreHintScope fp_denormals_ignore_scope;
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
String layerName = outputName;
|
String layerName = outputName;
|
||||||
|
|
||||||
if (layerName.empty())
|
if (layerName.empty())
|
||||||
@ -939,9 +938,6 @@ AsyncArray Net::Impl::forwardAsync(const String& outputName)
|
|||||||
isAsync = false;
|
isAsync = false;
|
||||||
|
|
||||||
return getBlobAsync(layerName);
|
return getBlobAsync(layerName);
|
||||||
#else
|
|
||||||
CV_Error(Error::StsNotImplemented, "DNN: Asynchronous forward requires build with enabled C++11");
|
|
||||||
#endif // CV_CXX11
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -273,11 +273,9 @@ struct Net::Impl : public detail::NetImplBase
|
|||||||
|
|
||||||
Mat getBlob(String outputName) const;
|
Mat getBlob(String outputName) const;
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
virtual AsyncArray getBlobAsync(const LayerPin& pin);
|
virtual AsyncArray getBlobAsync(const LayerPin& pin);
|
||||||
|
|
||||||
AsyncArray getBlobAsync(String outputName);
|
AsyncArray getBlobAsync(String outputName);
|
||||||
#endif // CV_CXX11
|
|
||||||
|
|
||||||
string dump(bool forceAllocation = false) const;
|
string dump(bool forceAllocation = false) const;
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#ifdef HAVE_PROTOBUF
|
#ifdef HAVE_PROTOBUF
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -1035,14 +1035,10 @@ TEST_P(Test_two_inputs, basic)
|
|||||||
randu(firstInp, 0, 100);
|
randu(firstInp, 0, 100);
|
||||||
randu(secondInp, 0, 100);
|
randu(secondInp, 0, 100);
|
||||||
|
|
||||||
#ifndef CV_CXX11
|
|
||||||
std::vector<String> input_names;
|
std::vector<String> input_names;
|
||||||
input_names.push_back("data");
|
input_names.push_back("data");
|
||||||
input_names.push_back("second_input");
|
input_names.push_back("second_input");
|
||||||
net.setInputsNames(input_names);
|
net.setInputsNames(input_names);
|
||||||
#else
|
|
||||||
net.setInputsNames({"data", "second_input"});
|
|
||||||
#endif
|
|
||||||
net.setInput(firstInp, "data", kScale);
|
net.setInput(firstInp, "data", kScale);
|
||||||
net.setInput(secondInp, "second_input", kScaleInv);
|
net.setInput(secondInp, "second_input", kScaleInv);
|
||||||
net.setPreferableBackend(backendId);
|
net.setPreferableBackend(backendId);
|
||||||
|
@ -210,15 +210,8 @@ struct ImageCodecInitializer
|
|||||||
static
|
static
|
||||||
ImageCodecInitializer& getCodecs()
|
ImageCodecInitializer& getCodecs()
|
||||||
{
|
{
|
||||||
#ifdef CV_CXX11
|
|
||||||
static ImageCodecInitializer g_codecs;
|
static ImageCodecInitializer g_codecs;
|
||||||
return g_codecs;
|
return g_codecs;
|
||||||
#else
|
|
||||||
// C++98 doesn't guarantee correctness of multi-threaded initialization of static global variables
|
|
||||||
// (memory leak here is not critical, use C++11 to avoid that)
|
|
||||||
static ImageCodecInitializer* g_codecs = new ImageCodecInitializer();
|
|
||||||
return *g_codecs;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,5 +52,7 @@
|
|||||||
#include "opencv2/core/private.hpp"
|
#include "opencv2/core/private.hpp"
|
||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "quirc.h"
|
#include "quirc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
@ -7,10 +7,6 @@
|
|||||||
#include "opencv2/ts.hpp"
|
#include "opencv2/ts.hpp"
|
||||||
#include "opencv2/objdetect.hpp"
|
#include "opencv2/objdetect.hpp"
|
||||||
|
|
||||||
#if defined CV_CXX11
|
|
||||||
#include <random>
|
#include <random>
|
||||||
#else
|
|
||||||
#include <cstdlib>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,16 +5,6 @@
|
|||||||
#include "test_precomp.hpp"
|
#include "test_precomp.hpp"
|
||||||
namespace opencv_test { namespace {
|
namespace opencv_test { namespace {
|
||||||
|
|
||||||
#if !defined CV_CXX11
|
|
||||||
// Wrapper for generating seeded random number via std::rand.
|
|
||||||
template<unsigned Seed>
|
|
||||||
class SeededRandFunctor {
|
|
||||||
public:
|
|
||||||
SeededRandFunctor() { std::srand(Seed); }
|
|
||||||
int operator()(int i) { return std::rand() % (i + 1); }
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string encode_qrcode_images_name[] = {
|
std::string encode_qrcode_images_name[] = {
|
||||||
"version1_mode1.png", "version1_mode2.png", "version1_mode4.png",
|
"version1_mode1.png", "version1_mode2.png", "version1_mode4.png",
|
||||||
"version2_mode1.png", "version2_mode2.png", "version2_mode4.png",
|
"version2_mode1.png", "version2_mode2.png", "version2_mode4.png",
|
||||||
|
@ -128,11 +128,7 @@ void pyPopulateArgumentConversionErrors()
|
|||||||
PySafeObject exception_message(PyObject_Str(exception_value));
|
PySafeObject exception_message(PyObject_Str(exception_value));
|
||||||
std::string message;
|
std::string message;
|
||||||
getUnicodeString(exception_message, message);
|
getUnicodeString(exception_message, message);
|
||||||
#ifdef CV_CXX11
|
|
||||||
conversionErrorsTLS.getRef().push_back(std::move(message));
|
conversionErrorsTLS.getRef().push_back(std::move(message));
|
||||||
#else
|
|
||||||
conversionErrorsTLS.getRef().push_back(message);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,8 +455,7 @@ class CppHeaderParser(object):
|
|||||||
("CV_INLINE", ""),
|
("CV_INLINE", ""),
|
||||||
("CV_DEPRECATED", ""),
|
("CV_DEPRECATED", ""),
|
||||||
("CV_DEPRECATED_EXTERNAL", ""),
|
("CV_DEPRECATED_EXTERNAL", ""),
|
||||||
("CV_NODISCARD_STD", ""),
|
("CV_NODISCARD_STD", "")]).strip()
|
||||||
("CV_NODISCARD", "")]).strip()
|
|
||||||
|
|
||||||
if decl_str.strip().startswith('virtual'):
|
if decl_str.strip().startswith('virtual'):
|
||||||
virtual_method = True
|
virtual_method = True
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
#include "opencv2/opencv_modules.hpp"
|
#include "opencv2/opencv_modules.hpp"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
@ -941,13 +941,9 @@ namespace opencv_test {
|
|||||||
using namespace cvtest;
|
using namespace cvtest;
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
|
||||||
#define CVTEST_GUARD_SYMBOL(name) \
|
#define CVTEST_GUARD_SYMBOL(name) \
|
||||||
class required_namespace_specificatin_here_for_symbol_ ## name {}; \
|
class required_namespace_specificatin_here_for_symbol_ ## name {}; \
|
||||||
using name = required_namespace_specificatin_here_for_symbol_ ## name;
|
using name = required_namespace_specificatin_here_for_symbol_ ## name;
|
||||||
#else
|
|
||||||
#define CVTEST_GUARD_SYMBOL(name) /* nothing */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CVTEST_GUARD_SYMBOL(norm)
|
CVTEST_GUARD_SYMBOL(norm)
|
||||||
CVTEST_GUARD_SYMBOL(add)
|
CVTEST_GUARD_SYMBOL(add)
|
||||||
|
@ -334,26 +334,11 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
// TODO: move to core::util?
|
// TODO: move to core::util?
|
||||||
#ifdef CV_CXX11
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
static void sleep_ms(int64 ms)
|
static void sleep_ms(int64 ms)
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
|
||||||
#include <time.h>
|
|
||||||
static void sleep_ms(int64 ms)
|
|
||||||
{
|
|
||||||
nanosleep(ms * 1000 * 1000);
|
|
||||||
}
|
|
||||||
#elif defined _WIN32
|
|
||||||
static void sleep_ms(int64 ms)
|
|
||||||
{
|
|
||||||
Sleep(ms);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#error "Can not detect sleep_ms() implementation"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// Linux specific
|
// Linux specific
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include <iterator>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#include <opencv2/core.hpp>
|
#include <opencv2/core.hpp>
|
||||||
#include <opencv2/imgcodecs.hpp>
|
#include <opencv2/imgcodecs.hpp>
|
||||||
|
|
||||||
|
#define PARALLEL_FOR_LAMBDA
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
@ -33,6 +35,8 @@ int mandelbrotFormula(const complex<float> &z0, const int maxIter=500) {
|
|||||||
}
|
}
|
||||||
//! [mandelbrot-grayscale-value]
|
//! [mandelbrot-grayscale-value]
|
||||||
|
|
||||||
|
#ifndef PARALLEL_FOR_LAMBDA
|
||||||
|
|
||||||
//! [mandelbrot-parallel]
|
//! [mandelbrot-parallel]
|
||||||
class ParallelMandelbrot : public ParallelLoopBody
|
class ParallelMandelbrot : public ParallelLoopBody
|
||||||
{
|
{
|
||||||
@ -71,6 +75,8 @@ private:
|
|||||||
};
|
};
|
||||||
//! [mandelbrot-parallel]
|
//! [mandelbrot-parallel]
|
||||||
|
|
||||||
|
#endif // !PARALLEL_FOR_LAMBDA
|
||||||
|
|
||||||
//! [mandelbrot-sequential]
|
//! [mandelbrot-sequential]
|
||||||
void sequentialMandelbrot(Mat &img, const float x1, const float y1, const float scaleX, const float scaleY)
|
void sequentialMandelbrot(Mat &img, const float x1, const float y1, const float scaleX, const float scaleY)
|
||||||
{
|
{
|
||||||
@ -102,7 +108,7 @@ int main()
|
|||||||
|
|
||||||
double t1 = (double) getTickCount();
|
double t1 = (double) getTickCount();
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
#ifdef PARALLEL_FOR_LAMBDA
|
||||||
|
|
||||||
//! [mandelbrot-parallel-call-cxx11]
|
//! [mandelbrot-parallel-call-cxx11]
|
||||||
parallel_for_(Range(0, mandelbrotImg.rows*mandelbrotImg.cols), [&](const Range& range){
|
parallel_for_(Range(0, mandelbrotImg.rows*mandelbrotImg.cols), [&](const Range& range){
|
||||||
@ -121,14 +127,14 @@ int main()
|
|||||||
});
|
});
|
||||||
//! [mandelbrot-parallel-call-cxx11]
|
//! [mandelbrot-parallel-call-cxx11]
|
||||||
|
|
||||||
#else
|
#else // PARALLEL_FOR_LAMBDA
|
||||||
|
|
||||||
//! [mandelbrot-parallel-call]
|
//! [mandelbrot-parallel-call]
|
||||||
ParallelMandelbrot parallelMandelbrot(mandelbrotImg, x1, y1, scaleX, scaleY);
|
ParallelMandelbrot parallelMandelbrot(mandelbrotImg, x1, y1, scaleX, scaleY);
|
||||||
parallel_for_(Range(0, mandelbrotImg.rows*mandelbrotImg.cols), parallelMandelbrot);
|
parallel_for_(Range(0, mandelbrotImg.rows*mandelbrotImg.cols), parallelMandelbrot);
|
||||||
//! [mandelbrot-parallel-call]
|
//! [mandelbrot-parallel-call]
|
||||||
|
|
||||||
#endif
|
#endif // PARALLEL_FOR_LAMBDA
|
||||||
|
|
||||||
t1 = ((double) getTickCount() - t1) / getTickFrequency();
|
t1 = ((double) getTickCount() - t1) / getTickFrequency();
|
||||||
cout << "Parallel Mandelbrot: " << t1 << " s" << endl;
|
cout << "Parallel Mandelbrot: " << t1 << " s" << endl;
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <opencv2/imgproc.hpp>
|
#include <opencv2/imgproc.hpp>
|
||||||
#include <opencv2/highgui.hpp>
|
#include <opencv2/highgui.hpp>
|
||||||
|
|
||||||
|
#define PARALLEL_FOR_LAMBDA
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
@ -47,7 +49,8 @@ void conv_seq(Mat src, Mat &dst, Mat kernel)
|
|||||||
}
|
}
|
||||||
//! [convolution-sequential]
|
//! [convolution-sequential]
|
||||||
|
|
||||||
#ifdef CV_CXX11
|
#ifdef PARALLEL_FOR_LAMBDA
|
||||||
|
|
||||||
void conv_parallel(Mat src, Mat &dst, Mat kernel)
|
void conv_parallel(Mat src, Mat &dst, Mat kernel)
|
||||||
{
|
{
|
||||||
int rows = src.rows, cols = src.cols;
|
int rows = src.rows, cols = src.cols;
|
||||||
@ -118,7 +121,8 @@ void conv_parallel_row_split(Mat src, Mat &dst, Mat kernel)
|
|||||||
});
|
});
|
||||||
//! [convolution-parallel-cxx11-row-split]
|
//! [convolution-parallel-cxx11-row-split]
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
#else // PARALLEL_FOR_LAMBDA
|
||||||
|
|
||||||
//! [convolution-parallel]
|
//! [convolution-parallel]
|
||||||
class parallelConvolution : public ParallelLoopBody
|
class parallelConvolution : public ParallelLoopBody
|
||||||
@ -235,7 +239,7 @@ void conv_parallel_row_split(Mat src, Mat &dst, Mat kernel)
|
|||||||
//! [convolution-parallel-function-row]
|
//! [convolution-parallel-function-row]
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // PARALLEL_FOR_LAMBDA
|
||||||
|
|
||||||
static void help(char *progName)
|
static void help(char *progName)
|
||||||
{
|
{
|
||||||
|
@ -59,12 +59,12 @@ int main(int,char**)
|
|||||||
cout << "C = " << endl << " " << C << endl << endl;
|
cout << "C = " << endl << " " << C << endl << endl;
|
||||||
//! [comma]
|
//! [comma]
|
||||||
// do the same with initializer_list
|
// do the same with initializer_list
|
||||||
#ifdef CV_CXX11
|
|
||||||
//! [list]
|
//! [list]
|
||||||
C = (Mat_<double>({0, -1, 0, -1, 5, -1, 0, -1, 0})).reshape(3);
|
C = (Mat_<double>({0, -1, 0, -1, 5, -1, 0, -1, 0})).reshape(3);
|
||||||
cout << "C = " << endl << " " << C << endl << endl;
|
cout << "C = " << endl << " " << C << endl << endl;
|
||||||
//! [list]
|
//! [list]
|
||||||
#endif
|
|
||||||
//! [clone]
|
//! [clone]
|
||||||
Mat RowClone = C.row(1).clone();
|
Mat RowClone = C.row(1).clone();
|
||||||
cout << "RowClone = " << endl << " " << RowClone << endl << endl;
|
cout << "RowClone = " << endl << " " << RowClone << endl << endl;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <opencv2/imgproc.hpp>
|
#include <opencv2/imgproc.hpp>
|
||||||
#include <opencv2/highgui.hpp>
|
#include <opencv2/highgui.hpp>
|
||||||
|
|
||||||
#if defined(CV_CXX11) && defined(HAVE_THREADS)
|
#if defined(HAVE_THREADS)
|
||||||
#define USE_THREADS 1
|
#define USE_THREADS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user