mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge branch 4.x
This commit is contained in:
@@ -1910,4 +1910,4 @@ DEFINE_SIMD_ALL(recip, recip_loop)
|
||||
#define SIMD_GUARD
|
||||
#endif
|
||||
|
||||
}} // cv::hal::
|
||||
}} // cv::hal::
|
||||
|
||||
+452
-566
File diff suppressed because it is too large
Load Diff
@@ -1,23 +0,0 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#ifndef OPENCV_CORE_SRC_DIRECTX_HPP
|
||||
#define OPENCV_CORE_SRC_DIRECTX_HPP
|
||||
|
||||
#ifndef HAVE_DIRECTX
|
||||
#error Invalid build configuration
|
||||
#endif
|
||||
|
||||
namespace cv {
|
||||
namespace directx {
|
||||
namespace internal {
|
||||
|
||||
struct OpenCLDirectXImpl;
|
||||
OpenCLDirectXImpl* createDirectXImpl();
|
||||
void deleteDirectXImpl(OpenCLDirectXImpl**);
|
||||
OpenCLDirectXImpl* getDirectXImpl(ocl::Context& ctx);
|
||||
|
||||
}}} // namespace internal
|
||||
|
||||
#endif // OPENCV_CORE_SRC_DIRECTX_HPP
|
||||
@@ -43,7 +43,9 @@
|
||||
#include "precomp.hpp"
|
||||
|
||||
#include "opencv2/core/utils/filesystem.hpp"
|
||||
#include "opencv2/core/utils/filesystem.private.hpp"
|
||||
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
#if defined _WIN32 || defined WINCE
|
||||
# include <windows.h>
|
||||
const char dir_separators[] = "/\\";
|
||||
@@ -131,12 +133,15 @@ namespace
|
||||
|
||||
|
||||
}
|
||||
#else
|
||||
#else // defined _WIN32 || defined WINCE
|
||||
# include <dirent.h>
|
||||
# include <sys/stat.h>
|
||||
const char dir_separators[] = "/";
|
||||
#endif
|
||||
#endif // defined _WIN32 || defined WINCE
|
||||
#endif // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
|
||||
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
static bool isDir(const cv::String& path, DIR* dir)
|
||||
{
|
||||
#if defined _WIN32 || defined _WIN32_WCE
|
||||
@@ -168,13 +173,20 @@ static bool isDir(const cv::String& path, DIR* dir)
|
||||
return is_dir != 0;
|
||||
#endif
|
||||
}
|
||||
#endif // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
|
||||
bool cv::utils::fs::isDirectory(const cv::String& path)
|
||||
{
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
CV_INSTRUMENT_REGION();
|
||||
return isDir(path, NULL);
|
||||
#else
|
||||
CV_UNUSED(path);
|
||||
CV_Error(Error::StsNotImplemented, "File system support is disabled in this OpenCV build!");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
static bool wildcmp(const char *string, const char *wild)
|
||||
{
|
||||
// Based on wildcmp written by Jack Handy - <A href="mailto:jakkhandy@hotmail.com">jakkhandy@hotmail.com</A>
|
||||
@@ -267,9 +279,11 @@ static void glob_rec(const cv::String& directory, const cv::String& wildchart, s
|
||||
CV_Error_(CV_StsObjectNotFound, ("could not open directory: %s", directory.c_str()));
|
||||
}
|
||||
}
|
||||
#endif // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
|
||||
void cv::glob(String pattern, std::vector<String>& result, bool recursive)
|
||||
{
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
CV_INSTRUMENT_REGION();
|
||||
|
||||
result.clear();
|
||||
@@ -303,20 +317,44 @@ void cv::glob(String pattern, std::vector<String>& result, bool recursive)
|
||||
|
||||
glob_rec(path, wildchart, result, recursive, false, path);
|
||||
std::sort(result.begin(), result.end());
|
||||
#else // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
CV_UNUSED(pattern);
|
||||
CV_UNUSED(result);
|
||||
CV_UNUSED(recursive);
|
||||
CV_Error(Error::StsNotImplemented, "File system support is disabled in this OpenCV build!");
|
||||
#endif // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
}
|
||||
|
||||
void cv::utils::fs::glob(const cv::String& directory, const cv::String& pattern,
|
||||
std::vector<cv::String>& result,
|
||||
bool recursive, bool includeDirectories)
|
||||
{
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
glob_rec(directory, pattern, result, recursive, includeDirectories, directory);
|
||||
std::sort(result.begin(), result.end());
|
||||
#else // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
CV_UNUSED(directory);
|
||||
CV_UNUSED(pattern);
|
||||
CV_UNUSED(result);
|
||||
CV_UNUSED(recursive);
|
||||
CV_UNUSED(includeDirectories);
|
||||
CV_Error(Error::StsNotImplemented, "File system support is disabled in this OpenCV build!");
|
||||
#endif // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
}
|
||||
|
||||
void cv::utils::fs::glob_relative(const cv::String& directory, const cv::String& pattern,
|
||||
std::vector<cv::String>& result,
|
||||
bool recursive, bool includeDirectories)
|
||||
{
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
glob_rec(directory, pattern, result, recursive, includeDirectories, cv::String());
|
||||
std::sort(result.begin(), result.end());
|
||||
#else // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
CV_UNUSED(directory);
|
||||
CV_UNUSED(pattern);
|
||||
CV_UNUSED(result);
|
||||
CV_UNUSED(recursive);
|
||||
CV_UNUSED(includeDirectories);
|
||||
CV_Error(Error::StsNotImplemented, "File system support is disabled in this OpenCV build!");
|
||||
#endif // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
}
|
||||
|
||||
+49
-33
@@ -113,10 +113,6 @@
|
||||
|
||||
#include "opencv2/core/opencl/runtime/opencl_core.hpp"
|
||||
|
||||
#ifdef HAVE_DIRECTX
|
||||
#include "directx.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCL_SVM
|
||||
#include "opencv2/core/opencl/runtime/opencl_svm_20.hpp"
|
||||
#include "opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp"
|
||||
@@ -2367,9 +2363,6 @@ protected:
|
||||
, contextId(CV_XADD(&g_contextId, 1))
|
||||
, configuration(configuration_)
|
||||
, handle(0)
|
||||
#ifdef HAVE_DIRECTX
|
||||
, p_directx_impl(0)
|
||||
#endif
|
||||
#ifdef HAVE_OPENCL_SVM
|
||||
, svmInitialized(false)
|
||||
#endif
|
||||
@@ -2395,11 +2388,10 @@ protected:
|
||||
handle = NULL;
|
||||
}
|
||||
devices.clear();
|
||||
#ifdef HAVE_DIRECTX
|
||||
directx::internal::deleteDirectXImpl(&p_directx_impl);
|
||||
#endif
|
||||
}
|
||||
|
||||
userContextStorage.clear();
|
||||
|
||||
{
|
||||
cv::AutoLock lock(cv::getInitializationMutex());
|
||||
auto& container = getGlobalContainer();
|
||||
@@ -2705,18 +2697,20 @@ public:
|
||||
return *bufferPoolHostPtr_.get();
|
||||
}
|
||||
|
||||
#ifdef HAVE_DIRECTX
|
||||
directx::internal::OpenCLDirectXImpl* p_directx_impl;
|
||||
|
||||
directx::internal::OpenCLDirectXImpl* getDirectXImpl()
|
||||
{
|
||||
if (!p_directx_impl)
|
||||
{
|
||||
p_directx_impl = directx::internal::createDirectXImpl();
|
||||
}
|
||||
return p_directx_impl;
|
||||
std::map<std::type_index, std::shared_ptr<UserContext>> userContextStorage;
|
||||
cv::Mutex userContextMutex;
|
||||
void setUserContext(std::type_index typeId, const std::shared_ptr<UserContext>& userContext) {
|
||||
cv::AutoLock lock(userContextMutex);
|
||||
userContextStorage[typeId] = userContext;
|
||||
}
|
||||
std::shared_ptr<UserContext> getUserContext(std::type_index typeId) {
|
||||
cv::AutoLock lock(userContextMutex);
|
||||
auto it = userContextStorage.find(typeId);
|
||||
if (it != userContextStorage.end())
|
||||
return it->second;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCL_SVM
|
||||
bool svmInitialized;
|
||||
@@ -3036,6 +3030,25 @@ Context Context::create(const std::string& configuration)
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void* Context::getOpenCLContextProperty(int propertyId) const
|
||||
{
|
||||
if (p == NULL)
|
||||
return nullptr;
|
||||
::size_t size = 0;
|
||||
CV_OCL_CHECK(clGetContextInfo(p->handle, CL_CONTEXT_PROPERTIES, 0, NULL, &size));
|
||||
std::vector<cl_context_properties> prop(size / sizeof(cl_context_properties), (cl_context_properties)0);
|
||||
CV_OCL_CHECK(clGetContextInfo(p->handle, CL_CONTEXT_PROPERTIES, size, prop.data(), NULL));
|
||||
for (size_t i = 0; i < prop.size(); i += 2)
|
||||
{
|
||||
if (prop[i] == (cl_context_properties)propertyId)
|
||||
{
|
||||
CV_LOG_DEBUG(NULL, "OpenCL: found context property=" << propertyId << ") => " << (void*)prop[i + 1]);
|
||||
return (void*)prop[i + 1];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL_SVM
|
||||
bool Context::useSVM() const
|
||||
{
|
||||
@@ -3097,6 +3110,21 @@ CV_EXPORTS bool useSVM(UMatUsageFlags usageFlags)
|
||||
} // namespace cv::ocl::svm
|
||||
#endif // HAVE_OPENCL_SVM
|
||||
|
||||
Context::UserContext::~UserContext()
|
||||
{
|
||||
}
|
||||
|
||||
void Context::setUserContext(std::type_index typeId, const std::shared_ptr<Context::UserContext>& userContext)
|
||||
{
|
||||
CV_Assert(p);
|
||||
p->setUserContext(typeId, userContext);
|
||||
}
|
||||
|
||||
std::shared_ptr<Context::UserContext> Context::getUserContext(std::type_index typeId)
|
||||
{
|
||||
CV_Assert(p);
|
||||
return p->getUserContext(typeId);
|
||||
}
|
||||
|
||||
static void get_platform_name(cl_platform_id id, String& name)
|
||||
{
|
||||
@@ -3454,7 +3482,6 @@ struct Kernel::Impl
|
||||
void registerImageArgument(int arg, const Image2D& image)
|
||||
{
|
||||
CV_CheckGE(arg, 0, "");
|
||||
CV_CheckLT(arg, (int)MAX_ARRS, "");
|
||||
if (arg < (int)shadow_images.size() && shadow_images[arg].ptr() != image.ptr()) // TODO future: replace ptr => impl (more strong check)
|
||||
{
|
||||
CV_Check(arg, !isInProgress, "ocl::Kernel: clearing of pending Image2D arguments is not allowed");
|
||||
@@ -7505,15 +7532,4 @@ uint64 Timer::durationNS() const
|
||||
|
||||
}} // namespace
|
||||
|
||||
#ifdef HAVE_DIRECTX
|
||||
namespace cv { namespace directx { namespace internal {
|
||||
OpenCLDirectXImpl* getDirectXImpl(ocl::Context& ctx)
|
||||
{
|
||||
ocl::Context::Impl* i = ctx.getImpl();
|
||||
CV_Assert(i);
|
||||
return i->getDirectXImpl();
|
||||
}
|
||||
}}} // namespace cv::directx::internal
|
||||
#endif
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
|
||||
@@ -172,9 +172,16 @@ Context& Context::getDefault(bool initialize)
|
||||
}
|
||||
void* Context::ptr() const { return NULL; }
|
||||
|
||||
void* Context::getOpenCLContextProperty(int /*propertyId*/) const { OCL_NOT_AVAILABLE(); }
|
||||
|
||||
bool Context::useSVM() const { return false; }
|
||||
void Context::setUseSVM(bool enabled) { }
|
||||
|
||||
Context::UserContext::~UserContext() { }
|
||||
|
||||
void Context::setUserContext(std::type_index /*typeId*/, const std::shared_ptr<Context::UserContext>& /*userContext*/) { OCL_NOT_AVAILABLE(); }
|
||||
std::shared_ptr<Context::UserContext> Context::getUserContext(std::type_index /*typeId*/) { OCL_NOT_AVAILABLE(); }
|
||||
|
||||
/* static */ Context Context::fromHandle(void* context) { OCL_NOT_AVAILABLE(); }
|
||||
/* static */ Context Context::fromDevice(const ocl::Device& device) { OCL_NOT_AVAILABLE(); }
|
||||
/* static */ Context Context::create(const std::string& configuration) { OCL_NOT_AVAILABLE(); }
|
||||
|
||||
@@ -375,6 +375,8 @@ cv::Mutex& getInitializationMutex();
|
||||
#define CV_SINGLETON_LAZY_INIT(TYPE, INITIALIZER) CV_SINGLETON_LAZY_INIT_(TYPE, INITIALIZER, instance)
|
||||
#define CV_SINGLETON_LAZY_INIT_REF(TYPE, INITIALIZER) CV_SINGLETON_LAZY_INIT_(TYPE, INITIALIZER, *instance)
|
||||
|
||||
CV_EXPORTS void releaseTlsStorageThread();
|
||||
|
||||
int cv_snprintf(char* buf, int len, const char* fmt, ...);
|
||||
int cv_vsnprintf(char* buf, int len, const char* fmt, va_list args);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@
|
||||
#include <opencv2/core/utils/tls.hpp>
|
||||
#include <opencv2/core/utils/instrumentation.hpp>
|
||||
|
||||
#include <opencv2/core/utils/filesystem.private.hpp>
|
||||
|
||||
namespace cv {
|
||||
|
||||
static void _initSystem()
|
||||
@@ -393,6 +395,7 @@ struct HWFeatures
|
||||
g_hwFeatureNames[CPU_VSX3] = "VSX3";
|
||||
|
||||
g_hwFeatureNames[CPU_MSA] = "CPU_MSA";
|
||||
g_hwFeatureNames[CPU_RISCVV] = "RISCVV";
|
||||
|
||||
g_hwFeatureNames[CPU_AVX512_COMMON] = "AVX512-COMMON";
|
||||
g_hwFeatureNames[CPU_AVX512_SKX] = "AVX512-SKX";
|
||||
@@ -588,6 +591,9 @@ struct HWFeatures
|
||||
#if defined _ARM_ && (defined(_WIN32_WCE) && _WIN32_WCE >= 0x800)
|
||||
have[CV_CPU_NEON] = true;
|
||||
#endif
|
||||
#ifdef __riscv_vector
|
||||
have[CV_CPU_RISCVV] = true;
|
||||
#endif
|
||||
#ifdef __mips_msa
|
||||
have[CV_CPU_MSA] = true;
|
||||
#endif
|
||||
@@ -947,6 +953,7 @@ String format( const char* fmt, ... )
|
||||
|
||||
String tempfile( const char* suffix )
|
||||
{
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
String fname;
|
||||
#ifndef NO_GETENV
|
||||
const char *temp_dir = getenv("OPENCV_TEMP_PATH");
|
||||
@@ -1033,6 +1040,10 @@ String tempfile( const char* suffix )
|
||||
return fname + suffix;
|
||||
}
|
||||
return fname;
|
||||
#else // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
CV_UNUSED(suffix);
|
||||
CV_Error(Error::StsNotImplemented, "File system support is disabled in this OpenCV build!");
|
||||
#endif // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
}
|
||||
|
||||
static ErrorCallback customErrorCallback = 0;
|
||||
@@ -1468,6 +1479,9 @@ struct ThreadData
|
||||
size_t idx; // Thread index in TLS storage. This is not OS thread ID!
|
||||
};
|
||||
|
||||
|
||||
static bool g_isTlsStorageInitialized = false;
|
||||
|
||||
// Main TLS storage class
|
||||
class TlsStorage
|
||||
{
|
||||
@@ -1477,6 +1491,7 @@ public:
|
||||
{
|
||||
tlsSlots.reserve(32);
|
||||
threads.reserve(32);
|
||||
g_isTlsStorageInitialized = true;
|
||||
}
|
||||
~TlsStorage()
|
||||
{
|
||||
@@ -1681,12 +1696,31 @@ static TlsStorage &getTlsStorage()
|
||||
#ifndef _WIN32 // pthread key destructor
|
||||
static void opencv_tls_destructor(void* pData)
|
||||
{
|
||||
if (!g_isTlsStorageInitialized)
|
||||
return; // nothing to release, so prefer to avoid creation of new global structures
|
||||
getTlsStorage().releaseThread(pData);
|
||||
}
|
||||
#else // _WIN32
|
||||
#ifdef CV_USE_FLS
|
||||
static void WINAPI opencv_fls_destructor(void* pData)
|
||||
{
|
||||
// Empiric detection of ExitProcess call
|
||||
DWORD code = STILL_ACTIVE/*259*/;
|
||||
BOOL res = GetExitCodeProcess(GetCurrentProcess(), &code);
|
||||
if (res && code != STILL_ACTIVE)
|
||||
{
|
||||
// Looks like we are in ExitProcess() call
|
||||
// This is FLS specific only because their callback is called before DllMain.
|
||||
// TLS doesn't have similar problem, DllMain() is called first which mark __termination properly.
|
||||
// Note: this workaround conflicts with ExitProcess() steps order described in documentation, however it works:
|
||||
// 3. ... called with DLL_PROCESS_DETACH
|
||||
// 7. The termination status of the process changes from STILL_ACTIVE to the exit value of the process.
|
||||
// (ref: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-exitprocess)
|
||||
cv::__termination = true;
|
||||
}
|
||||
|
||||
if (!g_isTlsStorageInitialized)
|
||||
return; // nothing to release, so prefer to avoid creation of new global structures
|
||||
getTlsStorage().releaseThread(pData);
|
||||
}
|
||||
#endif // CV_USE_FLS
|
||||
@@ -1695,6 +1729,13 @@ static void WINAPI opencv_fls_destructor(void* pData)
|
||||
} // namespace details
|
||||
using namespace details;
|
||||
|
||||
void releaseTlsStorageThread()
|
||||
{
|
||||
if (!g_isTlsStorageInitialized)
|
||||
return; // nothing to release, so prefer to avoid creation of new global structures
|
||||
getTlsStorage().releaseThread();
|
||||
}
|
||||
|
||||
TLSDataContainer::TLSDataContainer()
|
||||
{
|
||||
key_ = (int)getTlsStorage().reserveSlot(this); // Reserve key from TLS storage
|
||||
@@ -1778,7 +1819,7 @@ BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved)
|
||||
{
|
||||
// Not allowed to free resources if lpReserved is non-null
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583.aspx
|
||||
cv::getTlsStorage().releaseThread();
|
||||
releaseTlsStorageThread();
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "opencv2/core/utils/filesystem.hpp"
|
||||
|
||||
#include <opencv2/core/utils/configuration.private.hpp>
|
||||
#include "opencv2/core/utils/filesystem.private.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
@@ -67,6 +68,7 @@ CV_EXPORTS void addDataSearchSubDirectory(const cv::String& subdir)
|
||||
_getDataSearchSubDirectory().push_back(subdir);
|
||||
}
|
||||
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
static bool isPathSep(char c)
|
||||
{
|
||||
return c == '/' || c == '\\';
|
||||
@@ -96,12 +98,14 @@ static bool isSubDirectory_(const cv::String& base_path, const cv::String& path)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool isSubDirectory(const cv::String& base_path, const cv::String& path)
|
||||
{
|
||||
bool res = isSubDirectory_(base_path, path);
|
||||
CV_LOG_VERBOSE(NULL, 0, "isSubDirectory(): base: " << base_path << " path: " << path << " => result: " << (res ? "TRUE" : "FALSE"));
|
||||
return res;
|
||||
}
|
||||
#endif //OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
|
||||
static cv::String getModuleLocation(const void* addr)
|
||||
{
|
||||
@@ -188,6 +192,7 @@ cv::String findDataFile(const cv::String& relative_path,
|
||||
const std::vector<String>* search_paths,
|
||||
const std::vector<String>* subdir_paths)
|
||||
{
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
configuration_parameter = configuration_parameter ? configuration_parameter : "OPENCV_DATA_PATH";
|
||||
CV_LOG_DEBUG(NULL, cv::format("utils::findDataFile('%s', %s)", relative_path.c_str(), configuration_parameter));
|
||||
|
||||
@@ -410,10 +415,18 @@ cv::String findDataFile(const cv::String& relative_path,
|
||||
#endif
|
||||
|
||||
return cv::String(); // not found
|
||||
#else // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
CV_UNUSED(relative_path);
|
||||
CV_UNUSED(configuration_parameter);
|
||||
CV_UNUSED(search_paths);
|
||||
CV_UNUSED(subdir_paths);
|
||||
CV_Error(Error::StsNotImplemented, "File system support is disabled in this OpenCV build!");
|
||||
#endif // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
}
|
||||
|
||||
cv::String findDataFile(const cv::String& relative_path, bool required, const char* configuration_parameter)
|
||||
{
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
CV_LOG_DEBUG(NULL, cv::format("cv::utils::findDataFile('%s', %s, %s)",
|
||||
relative_path.c_str(), required ? "true" : "false",
|
||||
configuration_parameter ? configuration_parameter : "NULL"));
|
||||
@@ -424,6 +437,12 @@ cv::String findDataFile(const cv::String& relative_path, bool required, const ch
|
||||
if (result.empty() && required)
|
||||
CV_Error(cv::Error::StsError, cv::format("OpenCV: Can't find required data file: %s", relative_path.c_str()));
|
||||
return result;
|
||||
#else // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
CV_UNUSED(relative_path);
|
||||
CV_UNUSED(required);
|
||||
CV_UNUSED(configuration_parameter);
|
||||
CV_Error(Error::StsNotImplemented, "File system support is disabled in this OpenCV build!");
|
||||
#endif // OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_VERBOSE + 1
|
||||
#include "opencv2/core/utils/logger.hpp"
|
||||
#include "opencv2/core/utils/filesystem.hpp"
|
||||
#include "opencv2/core/utils/filesystem.private.hpp"
|
||||
|
||||
namespace cv { namespace samples {
|
||||
|
||||
@@ -49,6 +50,7 @@ CV_EXPORTS void addSamplesDataSearchSubDirectory(const cv::String& subdir)
|
||||
|
||||
cv::String findFile(const cv::String& relative_path, bool required, bool silentMode)
|
||||
{
|
||||
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
|
||||
CV_LOG_DEBUG(NULL, cv::format("cv::samples::findFile('%s', %s)", relative_path.c_str(), required ? "true" : "false"));
|
||||
cv::String result = cv::utils::findDataFile(relative_path,
|
||||
"OPENCV_SAMPLES_DATA_PATH",
|
||||
@@ -61,6 +63,12 @@ cv::String findFile(const cv::String& relative_path, bool required, bool silentM
|
||||
if (result.empty() && required)
|
||||
CV_Error(cv::Error::StsError, cv::format("OpenCV samples: Can't find required data file: %s", relative_path.c_str()));
|
||||
return result;
|
||||
#else
|
||||
CV_UNUSED(relative_path);
|
||||
CV_UNUSED(required);
|
||||
CV_UNUSED(silentMode);
|
||||
CV_Error(Error::StsNotImplemented, "File system support is disabled in this OpenCV build!");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
#include <opencv2/core/utils/logger.hpp>
|
||||
|
||||
#ifdef HAVE_VA
|
||||
# include <va/va.h>
|
||||
#else // HAVE_VA
|
||||
@@ -48,12 +50,28 @@ namespace cv { namespace va_intel {
|
||||
|
||||
#ifdef HAVE_VA_INTEL
|
||||
|
||||
static clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn clGetDeviceIDsFromVA_APIMediaAdapterINTEL = NULL;
|
||||
static clCreateFromVA_APIMediaSurfaceINTEL_fn clCreateFromVA_APIMediaSurfaceINTEL = NULL;
|
||||
static clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn clEnqueueAcquireVA_APIMediaSurfacesINTEL = NULL;
|
||||
static clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn clEnqueueReleaseVA_APIMediaSurfacesINTEL = NULL;
|
||||
|
||||
static bool contextInitialized = false;
|
||||
class VAAPIInterop : public ocl::Context::UserContext
|
||||
{
|
||||
public:
|
||||
VAAPIInterop(cl_platform_id platform) {
|
||||
clCreateFromVA_APIMediaSurfaceINTEL = (clCreateFromVA_APIMediaSurfaceINTEL_fn)
|
||||
clGetExtensionFunctionAddressForPlatform(platform, "clCreateFromVA_APIMediaSurfaceINTEL");
|
||||
clEnqueueAcquireVA_APIMediaSurfacesINTEL = (clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn)
|
||||
clGetExtensionFunctionAddressForPlatform(platform, "clEnqueueAcquireVA_APIMediaSurfacesINTEL");
|
||||
clEnqueueReleaseVA_APIMediaSurfacesINTEL = (clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn)
|
||||
clGetExtensionFunctionAddressForPlatform(platform, "clEnqueueReleaseVA_APIMediaSurfacesINTEL");
|
||||
if (!clCreateFromVA_APIMediaSurfaceINTEL ||
|
||||
!clEnqueueAcquireVA_APIMediaSurfacesINTEL ||
|
||||
!clEnqueueReleaseVA_APIMediaSurfacesINTEL) {
|
||||
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't get extension function for VA-API interop");
|
||||
}
|
||||
}
|
||||
virtual ~VAAPIInterop() {
|
||||
}
|
||||
clCreateFromVA_APIMediaSurfaceINTEL_fn clCreateFromVA_APIMediaSurfaceINTEL;
|
||||
clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn clEnqueueAcquireVA_APIMediaSurfacesINTEL;
|
||||
clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn clEnqueueReleaseVA_APIMediaSurfacesINTEL;
|
||||
};
|
||||
|
||||
#endif // HAVE_VA_INTEL
|
||||
|
||||
@@ -65,10 +83,8 @@ Context& initializeContextFromVA(VADisplay display, bool tryInterop)
|
||||
#if !defined(HAVE_VA)
|
||||
NO_VA_SUPPORT_ERROR;
|
||||
#else // !HAVE_VA
|
||||
init_libva();
|
||||
|
||||
# ifdef HAVE_VA_INTEL
|
||||
contextInitialized = false;
|
||||
if (tryInterop)
|
||||
{
|
||||
cl_uint numPlatforms;
|
||||
@@ -97,20 +113,10 @@ Context& initializeContextFromVA(VADisplay display, bool tryInterop)
|
||||
for (int i = 0; i < (int)numPlatforms; ++i)
|
||||
{
|
||||
// Get extension function pointers
|
||||
|
||||
clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn clGetDeviceIDsFromVA_APIMediaAdapterINTEL;
|
||||
clGetDeviceIDsFromVA_APIMediaAdapterINTEL = (clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn)
|
||||
clGetExtensionFunctionAddressForPlatform(platforms[i], "clGetDeviceIDsFromVA_APIMediaAdapterINTEL");
|
||||
clCreateFromVA_APIMediaSurfaceINTEL = (clCreateFromVA_APIMediaSurfaceINTEL_fn)
|
||||
clGetExtensionFunctionAddressForPlatform(platforms[i], "clCreateFromVA_APIMediaSurfaceINTEL");
|
||||
clEnqueueAcquireVA_APIMediaSurfacesINTEL = (clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn)
|
||||
clGetExtensionFunctionAddressForPlatform(platforms[i], "clEnqueueAcquireVA_APIMediaSurfacesINTEL");
|
||||
clEnqueueReleaseVA_APIMediaSurfacesINTEL = (clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn)
|
||||
clGetExtensionFunctionAddressForPlatform(platforms[i], "clEnqueueReleaseVA_APIMediaSurfacesINTEL");
|
||||
|
||||
if (((void*)clGetDeviceIDsFromVA_APIMediaAdapterINTEL == NULL) ||
|
||||
((void*)clCreateFromVA_APIMediaSurfaceINTEL == NULL) ||
|
||||
((void*)clEnqueueAcquireVA_APIMediaSurfacesINTEL == NULL) ||
|
||||
((void*)clEnqueueReleaseVA_APIMediaSurfacesINTEL == NULL))
|
||||
if ((void*)clGetDeviceIDsFromVA_APIMediaAdapterINTEL == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -151,8 +157,6 @@ Context& initializeContextFromVA(VADisplay display, bool tryInterop)
|
||||
|
||||
if (found >= 0)
|
||||
{
|
||||
contextInitialized = true;
|
||||
|
||||
cl_platform_id platform = platforms[found];
|
||||
std::string platformName = PlatformInfo(&platform).name();
|
||||
|
||||
@@ -160,6 +164,7 @@ Context& initializeContextFromVA(VADisplay display, bool tryInterop)
|
||||
try
|
||||
{
|
||||
clExecCtx = OpenCLExecutionContext::create(platformName, platform, context, device);
|
||||
clExecCtx.getContext().setUserContext(std::make_shared<VAAPIInterop>(platform));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -520,7 +525,6 @@ void convertToVASurface(VADisplay display, InputArray src, VASurfaceID surface,
|
||||
#if !defined(HAVE_VA)
|
||||
NO_VA_SUPPORT_ERROR;
|
||||
#else // !HAVE_VA
|
||||
init_libva();
|
||||
|
||||
const int stype = CV_8UC3;
|
||||
|
||||
@@ -531,7 +535,18 @@ void convertToVASurface(VADisplay display, InputArray src, VASurfaceID surface,
|
||||
CV_Assert(srcSize.width == size.width && srcSize.height == size.height);
|
||||
|
||||
#ifdef HAVE_VA_INTEL
|
||||
if (contextInitialized)
|
||||
ocl::OpenCLExecutionContext& ocl_context = ocl::OpenCLExecutionContext::getCurrent();
|
||||
VAAPIInterop* interop = ocl_context.getContext().getUserContext<VAAPIInterop>().get();
|
||||
CV_LOG_IF_DEBUG(NULL, !interop,
|
||||
"OpenCL/VA_INTEL: Can't interop with current OpenCL context - missing VAAPIInterop API. "
|
||||
"OpenCL context should be created through initializeContextFromVA()");
|
||||
void* context_display = ocl_context.getContext().getOpenCLContextProperty(CL_CONTEXT_VA_API_DISPLAY_INTEL);
|
||||
CV_LOG_IF_INFO(NULL, interop && !context_display,
|
||||
"OpenCL/VA_INTEL: Can't interop with current OpenCL context - missing VA display, context re-creation is required");
|
||||
bool isValidContextDisplay = (display == context_display);
|
||||
CV_LOG_IF_INFO(NULL, interop && context_display && !isValidContextDisplay,
|
||||
"OpenCL/VA_INTEL: Can't interop with current OpenCL context - VA display mismatch: " << context_display << "(context) vs " << (void*)display << "(surface)");
|
||||
if (isValidContextDisplay && interop)
|
||||
{
|
||||
UMat u = src.getUMat();
|
||||
|
||||
@@ -541,28 +556,26 @@ void convertToVASurface(VADisplay display, InputArray src, VASurfaceID surface,
|
||||
|
||||
cl_mem clBuffer = (cl_mem)u.handle(ACCESS_READ);
|
||||
|
||||
using namespace cv::ocl;
|
||||
Context& ctx = Context::getDefault();
|
||||
cl_context context = (cl_context)ctx.ptr();
|
||||
cl_context context = (cl_context)ocl_context.getContext().ptr();
|
||||
|
||||
cl_int status = 0;
|
||||
|
||||
cl_mem clImageY = clCreateFromVA_APIMediaSurfaceINTEL(context, CL_MEM_WRITE_ONLY, &surface, 0, &status);
|
||||
cl_mem clImageY = interop->clCreateFromVA_APIMediaSurfaceINTEL(context, CL_MEM_WRITE_ONLY, &surface, 0, &status);
|
||||
if (status != CL_SUCCESS)
|
||||
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromVA_APIMediaSurfaceINTEL failed (Y plane)");
|
||||
cl_mem clImageUV = clCreateFromVA_APIMediaSurfaceINTEL(context, CL_MEM_WRITE_ONLY, &surface, 1, &status);
|
||||
cl_mem clImageUV = interop->clCreateFromVA_APIMediaSurfaceINTEL(context, CL_MEM_WRITE_ONLY, &surface, 1, &status);
|
||||
if (status != CL_SUCCESS)
|
||||
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromVA_APIMediaSurfaceINTEL failed (UV plane)");
|
||||
|
||||
cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr();
|
||||
cl_command_queue q = (cl_command_queue)ocl_context.getQueue().ptr();
|
||||
|
||||
cl_mem images[2] = { clImageY, clImageUV };
|
||||
status = clEnqueueAcquireVA_APIMediaSurfacesINTEL(q, 2, images, 0, NULL, NULL);
|
||||
status = interop->clEnqueueAcquireVA_APIMediaSurfacesINTEL(q, 2, images, 0, NULL, NULL);
|
||||
if (status != CL_SUCCESS)
|
||||
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueAcquireVA_APIMediaSurfacesINTEL failed");
|
||||
if (!ocl::ocl_convert_bgr_to_nv12(clBuffer, (int)u.step[0], u.cols, u.rows, clImageY, clImageUV))
|
||||
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: ocl_convert_bgr_to_nv12 failed");
|
||||
clEnqueueReleaseVA_APIMediaSurfacesINTEL(q, 2, images, 0, NULL, NULL);
|
||||
interop->clEnqueueReleaseVA_APIMediaSurfacesINTEL(q, 2, images, 0, NULL, NULL);
|
||||
if (status != CL_SUCCESS)
|
||||
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueReleaseVA_APIMediaSurfacesINTEL failed");
|
||||
|
||||
@@ -580,6 +593,7 @@ void convertToVASurface(VADisplay display, InputArray src, VASurfaceID surface,
|
||||
else
|
||||
# endif // HAVE_VA_INTEL
|
||||
{
|
||||
init_libva();
|
||||
Mat m = src.getMat();
|
||||
|
||||
// TODO Add support for roi
|
||||
@@ -626,7 +640,6 @@ void convertFromVASurface(VADisplay display, VASurfaceID surface, Size size, Out
|
||||
#if !defined(HAVE_VA)
|
||||
NO_VA_SUPPORT_ERROR;
|
||||
#else // !HAVE_VA
|
||||
init_libva();
|
||||
|
||||
const int dtype = CV_8UC3;
|
||||
|
||||
@@ -634,7 +647,9 @@ void convertFromVASurface(VADisplay display, VASurfaceID surface, Size size, Out
|
||||
dst.create(size, dtype);
|
||||
|
||||
#ifdef HAVE_VA_INTEL
|
||||
if (contextInitialized)
|
||||
ocl::OpenCLExecutionContext& ocl_context = ocl::OpenCLExecutionContext::getCurrent();
|
||||
VAAPIInterop* interop = ocl_context.getContext().getUserContext<VAAPIInterop>().get();
|
||||
if (display == ocl_context.getContext().getOpenCLContextProperty(CL_CONTEXT_VA_API_DISPLAY_INTEL) && interop)
|
||||
{
|
||||
UMat u = dst.getUMat();
|
||||
|
||||
@@ -644,28 +659,26 @@ void convertFromVASurface(VADisplay display, VASurfaceID surface, Size size, Out
|
||||
|
||||
cl_mem clBuffer = (cl_mem)u.handle(ACCESS_WRITE);
|
||||
|
||||
using namespace cv::ocl;
|
||||
Context& ctx = Context::getDefault();
|
||||
cl_context context = (cl_context)ctx.ptr();
|
||||
cl_context context = (cl_context)ocl_context.getContext().ptr();
|
||||
|
||||
cl_int status = 0;
|
||||
|
||||
cl_mem clImageY = clCreateFromVA_APIMediaSurfaceINTEL(context, CL_MEM_READ_ONLY, &surface, 0, &status);
|
||||
cl_mem clImageY = interop->clCreateFromVA_APIMediaSurfaceINTEL(context, CL_MEM_READ_ONLY, &surface, 0, &status);
|
||||
if (status != CL_SUCCESS)
|
||||
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromVA_APIMediaSurfaceINTEL failed (Y plane)");
|
||||
cl_mem clImageUV = clCreateFromVA_APIMediaSurfaceINTEL(context, CL_MEM_READ_ONLY, &surface, 1, &status);
|
||||
cl_mem clImageUV = interop->clCreateFromVA_APIMediaSurfaceINTEL(context, CL_MEM_READ_ONLY, &surface, 1, &status);
|
||||
if (status != CL_SUCCESS)
|
||||
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clCreateFromVA_APIMediaSurfaceINTEL failed (UV plane)");
|
||||
|
||||
cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr();
|
||||
cl_command_queue q = (cl_command_queue)ocl_context.getQueue().ptr();
|
||||
|
||||
cl_mem images[2] = { clImageY, clImageUV };
|
||||
status = clEnqueueAcquireVA_APIMediaSurfacesINTEL(q, 2, images, 0, NULL, NULL);
|
||||
status = interop->clEnqueueAcquireVA_APIMediaSurfacesINTEL(q, 2, images, 0, NULL, NULL);
|
||||
if (status != CL_SUCCESS)
|
||||
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueAcquireVA_APIMediaSurfacesINTEL failed");
|
||||
if (!ocl::ocl_convert_nv12_to_bgr(clImageY, clImageUV, clBuffer, (int)u.step[0], u.cols, u.rows))
|
||||
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: ocl_convert_nv12_to_bgr failed");
|
||||
status = clEnqueueReleaseVA_APIMediaSurfacesINTEL(q, 2, images, 0, NULL, NULL);
|
||||
status = interop->clEnqueueReleaseVA_APIMediaSurfacesINTEL(q, 2, images, 0, NULL, NULL);
|
||||
if (status != CL_SUCCESS)
|
||||
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clEnqueueReleaseVA_APIMediaSurfacesINTEL failed");
|
||||
|
||||
@@ -683,6 +696,7 @@ void convertFromVASurface(VADisplay display, VASurfaceID surface, Size size, Out
|
||||
else
|
||||
# endif // HAVE_VA_INTEL
|
||||
{
|
||||
init_libva();
|
||||
Mat m = dst.getMat();
|
||||
|
||||
// TODO Add support for roi
|
||||
|
||||
Reference in New Issue
Block a user