mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge branch 4.x
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "precomp.hpp"
|
||||
//#undef CV_CXX11 // debug non C++11 mode
|
||||
#include "opencv2/core/async.hpp"
|
||||
#include "opencv2/core/detail/async_promise.hpp"
|
||||
|
||||
@@ -16,11 +15,9 @@
|
||||
|
||||
#ifndef OPENCV_DISABLE_THREAD_SUPPORT
|
||||
|
||||
#ifdef CV_CXX11
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <chrono>
|
||||
#endif
|
||||
|
||||
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; } \
|
||||
int refcount_promise;
|
||||
|
||||
#ifdef CV_CXX11
|
||||
mutable std::mutex mtx;
|
||||
mutable std::condition_variable cond_var;
|
||||
#else
|
||||
mutable cv::Mutex mtx;
|
||||
#endif
|
||||
|
||||
mutable bool has_result; // Mat, UMat or exception
|
||||
|
||||
@@ -88,11 +81,7 @@ struct AsyncArray::Impl
|
||||
if (!wait_for(timeoutNs))
|
||||
return false;
|
||||
}
|
||||
#ifdef CV_CXX11
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
#else
|
||||
cv::AutoLock lock(mtx);
|
||||
#endif
|
||||
if (has_result)
|
||||
{
|
||||
if (!result_mat.empty())
|
||||
@@ -145,7 +134,6 @@ struct AsyncArray::Impl
|
||||
if (timeoutNs == 0)
|
||||
return has_result;
|
||||
CV_LOG_INFO(NULL, "Waiting for async result ...");
|
||||
#ifdef CV_CXX11
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
const auto cond_pred = [&]{ return has_result == true; };
|
||||
if (timeoutNs > 0)
|
||||
@@ -156,9 +144,6 @@ struct AsyncArray::Impl
|
||||
CV_Assert(has_result);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
CV_Error(Error::StsNotImplemented, "OpenCV has been built without async waiting support (C++11 is required)");
|
||||
#endif
|
||||
}
|
||||
|
||||
AsyncArray getArrayResult()
|
||||
@@ -175,11 +160,7 @@ struct AsyncArray::Impl
|
||||
{
|
||||
if (future_is_returned && refcount_future == 0)
|
||||
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
||||
#ifdef CV_CXX11
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
#else
|
||||
cv::AutoLock lock(mtx);
|
||||
#endif
|
||||
CV_Assert(!has_result);
|
||||
int k = value.kind();
|
||||
if (k == _InputArray::UMAT)
|
||||
@@ -193,9 +174,7 @@ struct AsyncArray::Impl
|
||||
value.copyTo(*result_mat.get());
|
||||
}
|
||||
has_result = true;
|
||||
#ifdef CV_CXX11
|
||||
cond_var.notify_all();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CV__EXCEPTION_PTR
|
||||
@@ -203,18 +182,12 @@ struct AsyncArray::Impl
|
||||
{
|
||||
if (future_is_returned && refcount_future == 0)
|
||||
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
||||
#ifdef CV_CXX11
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
#else
|
||||
cv::AutoLock lock(mtx);
|
||||
#endif
|
||||
CV_Assert(!has_result);
|
||||
has_exception = true;
|
||||
exception = e;
|
||||
has_result = true;
|
||||
#ifdef CV_CXX11
|
||||
cond_var.notify_all();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -222,18 +195,12 @@ struct AsyncArray::Impl
|
||||
{
|
||||
if (future_is_returned && refcount_future == 0)
|
||||
CV_Error(Error::StsError, "Associated AsyncArray has been destroyed");
|
||||
#ifdef CV_CXX11
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
#else
|
||||
cv::AutoLock lock(mtx);
|
||||
#endif
|
||||
CV_Assert(!has_result);
|
||||
has_exception = true;
|
||||
cv_exception = e;
|
||||
has_result = true;
|
||||
#ifdef CV_CXX11
|
||||
cond_var.notify_all();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1952,12 +1952,7 @@ void _OutputArray::move(UMat& u) const
|
||||
int k = kind();
|
||||
if (k == UMAT)
|
||||
{
|
||||
#ifdef CV_CXX11
|
||||
*(UMat*)obj = std::move(u);
|
||||
#else
|
||||
*(UMat*)obj = u;
|
||||
u.release();
|
||||
#endif
|
||||
}
|
||||
else if (k == MAT)
|
||||
{
|
||||
@@ -1992,12 +1987,7 @@ void _OutputArray::move(Mat& m) const
|
||||
}
|
||||
else if (k == MAT)
|
||||
{
|
||||
#ifdef CV_CXX11
|
||||
*(Mat*)obj = std::move(m);
|
||||
#else
|
||||
*(Mat*)obj = m;
|
||||
m.release();
|
||||
#endif
|
||||
}
|
||||
else if (k == MATX)
|
||||
{
|
||||
|
||||
@@ -912,8 +912,7 @@ int getNumberOfCPUs_()
|
||||
* 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.
|
||||
*/
|
||||
#if defined CV_CXX11 \
|
||||
&& !defined(__MINGW32__) /* not implemented (2020-03) */ \
|
||||
#if !defined(__MINGW32__) /* not implemented (2020-03) */
|
||||
|
||||
/*
|
||||
* Check for this standard C++11 way, we do not return directly because
|
||||
|
||||
+11
-42
@@ -120,11 +120,15 @@ void* allocSingletonNewBuffer(size_t size) { return malloc(size); }
|
||||
#include <cstdlib> // std::abort
|
||||
#endif
|
||||
|
||||
#if defined __ANDROID__ || defined __unix__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __HAIKU__ || defined __Fuchsia__
|
||||
#if defined __ANDROID__ || defined __unix__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __HAIKU__ || defined __Fuchsia__ || defined __QNX__
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
#if defined __QNX__
|
||||
# include <sys/elf.h>
|
||||
# include <sys/auxv.h>
|
||||
using Elf64_auxv_t = auxv64_t;
|
||||
# include <elfdefinitions.h>
|
||||
const uint64_t AT_HWCAP = NT_GNU_HWCAP;
|
||||
#else
|
||||
# include <elf.h>
|
||||
#endif
|
||||
@@ -251,7 +255,7 @@ std::wstring GetTempFileNameWinRT(std::wstring prefix)
|
||||
#include "omp.h"
|
||||
#endif
|
||||
|
||||
#if defined __unix__ || defined __APPLE__ || defined __EMSCRIPTEN__ || defined __FreeBSD__ || defined __GLIBC__ || defined __HAIKU__
|
||||
#if defined __unix__ || defined __APPLE__ || defined __EMSCRIPTEN__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __GLIBC__ || defined __HAIKU__
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
@@ -301,9 +305,7 @@ DECLARE_CV_CPUID_X86
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined CV_CXX11
|
||||
#include <chrono>
|
||||
#endif
|
||||
#include <chrono>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
@@ -562,7 +564,7 @@ struct HWFeatures
|
||||
}
|
||||
#endif // CV_CPUID_X86
|
||||
|
||||
#if defined __ANDROID__ || defined __linux__ || defined __FreeBSD__ || defined __QNX__
|
||||
#if defined __ANDROID__ || defined __linux__ || defined __QNX__
|
||||
#ifdef __aarch64__
|
||||
have[CV_CPU_NEON] = true;
|
||||
have[CV_CPU_FP16] = true;
|
||||
@@ -581,10 +583,12 @@ struct HWFeatures
|
||||
have[CV_CPU_NEON_DOTPROD] = (auxv.a_un.a_val & (1 << 20)) != 0; // HWCAP_ASIMDDP
|
||||
have[CV_CPU_NEON_FP16] = (auxv.a_un.a_val & (1 << 10)) != 0; // HWCAP_ASIMDHP
|
||||
}
|
||||
#if defined(AT_HWCAP2)
|
||||
else if (auxv.a_type == AT_HWCAP2)
|
||||
{
|
||||
have[CV_CPU_NEON_BF16] = (auxv.a_un.a_val & (1 << 14)) != 0; // HWCAP2_BF16
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
close(cpufile);
|
||||
@@ -611,7 +615,7 @@ struct HWFeatures
|
||||
CV_LOG_INFO(NULL, "- FP16 instructions is NOT enabled via build flags");
|
||||
#endif
|
||||
#endif
|
||||
#elif defined __arm__ && !defined __FreeBSD__
|
||||
#elif defined __arm__
|
||||
int cpufile = open("/proc/self/auxv", O_RDONLY);
|
||||
|
||||
if (cpufile >= 0)
|
||||
@@ -903,50 +907,15 @@ bool useOptimized(void)
|
||||
|
||||
int64 getTickCount(void)
|
||||
{
|
||||
#if defined CV_CXX11
|
||||
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||
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)
|
||||
{
|
||||
#if defined CV_CXX11
|
||||
using clock_period_t = std::chrono::steady_clock::duration::period;
|
||||
double clock_freq = clock_period_t::den / clock_period_t::num;
|
||||
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__)
|
||||
|
||||
Reference in New Issue
Block a user