build: made environment access a separate feature

This commit is contained in:
Maksim Shabunin 2024-10-17 23:35:38 +03:00
parent 2756c20e3e
commit 04818d6dd5
44 changed files with 176 additions and 275 deletions

View File

@ -536,6 +536,7 @@ OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn'
OCV_OPTION(OPENCV_ENABLE_MEMALIGN "Enable posix_memalign or memalign usage" ON) OCV_OPTION(OPENCV_ENABLE_MEMALIGN "Enable posix_memalign or memalign usage" ON)
OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF) OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF)
OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF) OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF)
OCV_OPTION(OPENCV_DISABLE_ENV_SUPPORT "Disable environment variables access (getenv)" (CMAKE_SYSTEM_NAME MATCHES "Windows(CE|Phone|Store)"))
OCV_OPTION(OPENCV_SEMIHOSTING "Build the library for semihosting target (Arm). See https://developer.arm.com/documentation/100863/latest." OFF) OCV_OPTION(OPENCV_SEMIHOSTING "Build the library for semihosting target (Arm). See https://developer.arm.com/documentation/100863/latest." OFF)
OCV_OPTION(ENABLE_CUDA_FIRST_CLASS_LANGUAGE "Enable CUDA as a first class language, if enabled dependant projects will need to use CMake >= 3.18" OFF OCV_OPTION(ENABLE_CUDA_FIRST_CLASS_LANGUAGE "Enable CUDA as a first class language, if enabled dependant projects will need to use CMake >= 3.18" OFF
VISIBLE_IF (WITH_CUDA AND NOT CMAKE_VERSION VERSION_LESS 3.18) VISIBLE_IF (WITH_CUDA AND NOT CMAKE_VERSION VERSION_LESS 3.18)

View File

@ -1,6 +1,6 @@
set(WINRT TRUE) set(WINRT TRUE)
add_definitions(-DWINRT -DNO_GETENV) add_definitions(-DWINRT)
# Making definitions available to other configurations and # Making definitions available to other configurations and
# to filter dependency restrictions at compile time. # to filter dependency restrictions at compile time.

View File

@ -1 +1 @@
add_definitions(-DNO_GETENV) # empty

View File

@ -59,7 +59,6 @@ import cv2 # variables set after this may not have effect
## Types ## Types
- _non-null_ - set to anything to enable feature, in some cases can be interpreted as other types (e.g. path)
- _bool_ - `1`, `True`, `true`, `TRUE` / `0`, `False`, `false`, `FALSE` - _bool_ - `1`, `True`, `true`, `TRUE` / `0`, `False`, `false`, `FALSE`
- _number_/_size_ - unsigned number, suffixes `MB`, `Mb`, `mb`, `KB`, `Kb`, `kb` - _number_/_size_ - unsigned number, suffixes `MB`, `Mb`, `mb`, `KB`, `Kb`, `kb`
- _string_ - plain string or can have a structure - _string_ - plain string or can have a structure
@ -70,7 +69,7 @@ import cv2 # variables set after this may not have effect
## General, core ## General, core
| name | type | default | description | | name | type | default | description |
|------|------|---------|-------------| |------|------|---------|-------------|
| OPENCV_SKIP_CPU_BASELINE_CHECK | non-null | | do not check that current CPU supports all features used by the build (baseline) | | OPENCV_SKIP_CPU_BASELINE_CHECK | bool | false | do not check that current CPU supports all features used by the build (baseline) |
| OPENCV_CPU_DISABLE | `,` or `;`-separated | | disable code branches which use CPU features (dispatched code) | | OPENCV_CPU_DISABLE | `,` or `;`-separated | | disable code branches which use CPU features (dispatched code) |
| OPENCV_SETUP_TERMINATE_HANDLER | bool | true (Windows) | use std::set_terminate to install own termination handler | | OPENCV_SETUP_TERMINATE_HANDLER | bool | true (Windows) | use std::set_terminate to install own termination handler |
| OPENCV_LIBVA_RUNTIME | file path | | libva for VA interoperability utils | | OPENCV_LIBVA_RUNTIME | file path | | libva for VA interoperability utils |
@ -78,9 +77,9 @@ import cv2 # variables set after this may not have effect
| OPENCV_BUFFER_AREA_ALWAYS_SAFE | bool | false | enable safe mode for multi-buffer allocations (each buffer separately) | | OPENCV_BUFFER_AREA_ALWAYS_SAFE | bool | false | enable safe mode for multi-buffer allocations (each buffer separately) |
| OPENCV_KMEANS_PARALLEL_GRANULARITY | num | 1000 | tune algorithm parallel work distribution parameter `parallel_for_(..., ..., ..., granularity)` | | OPENCV_KMEANS_PARALLEL_GRANULARITY | num | 1000 | tune algorithm parallel work distribution parameter `parallel_for_(..., ..., ..., granularity)` |
| OPENCV_DUMP_ERRORS | bool | true (Debug or Android), false (others) | print extra information on exception (log to Android) | | OPENCV_DUMP_ERRORS | bool | true (Debug or Android), false (others) | print extra information on exception (log to Android) |
| OPENCV_DUMP_CONFIG | non-null | | print build configuration to stderr (`getBuildInformation`) | | OPENCV_DUMP_CONFIG | bool | false | print build configuration to stderr (`getBuildInformation`) |
| OPENCV_PYTHON_DEBUG | bool | false | enable extra warnings in Python bindings | | OPENCV_PYTHON_DEBUG | bool | false | enable extra warnings in Python bindings |
| OPENCV_TEMP_PATH | non-null / path | `/tmp/` (Linux), `/data/local/tmp/` (Android), `GetTempPathA` (Windows) | directory for temporary files | | OPENCV_TEMP_PATH | path | `/tmp/` (Linux), `/data/local/tmp/` (Android), `GetTempPathA` (Windows) | directory for temporary files |
| OPENCV_DATA_PATH_HINT | paths | | paths for findDataFile | | OPENCV_DATA_PATH_HINT | paths | | paths for findDataFile |
| OPENCV_DATA_PATH | paths | | paths for findDataFile | | OPENCV_DATA_PATH | paths | | paths for findDataFile |
| OPENCV_SAMPLES_DATA_PATH_HINT | paths | | paths for findDataFile | | OPENCV_SAMPLES_DATA_PATH_HINT | paths | | paths for findDataFile |
@ -272,7 +271,7 @@ Some external dependencies can be detached into a dynamic library, which will be
| ⭐ OPENCV_FFMPEG_CAPTURE_OPTIONS | string (see note) | | extra options for VideoCapture FFmpeg backend | | ⭐ OPENCV_FFMPEG_CAPTURE_OPTIONS | string (see note) | | extra options for VideoCapture FFmpeg backend |
| ⭐ OPENCV_FFMPEG_WRITER_OPTIONS | string (see note) | | extra options for VideoWriter FFmpeg backend | | ⭐ OPENCV_FFMPEG_WRITER_OPTIONS | string (see note) | | extra options for VideoWriter FFmpeg backend |
| OPENCV_FFMPEG_THREADS | num | | set FFmpeg thread count | | OPENCV_FFMPEG_THREADS | num | | set FFmpeg thread count |
| OPENCV_FFMPEG_DEBUG | non-null | | enable logging messages from FFmpeg | | OPENCV_FFMPEG_DEBUG | bool | false | enable logging messages from FFmpeg |
| OPENCV_FFMPEG_LOGLEVEL | num | | set FFmpeg logging level | | OPENCV_FFMPEG_LOGLEVEL | num | | set FFmpeg logging level |
| OPENCV_FFMPEG_DLL_DIR | dir path | | directory with FFmpeg plugin (legacy) | | OPENCV_FFMPEG_DLL_DIR | dir path | | directory with FFmpeg plugin (legacy) |
| OPENCV_FFMPEG_IS_THREAD_SAFE | bool | false | enabling this option will turn off thread safety locks in the FFmpeg backend (use only if you are sure FFmpeg is built with threading support, tested on Linux) | | OPENCV_FFMPEG_IS_THREAD_SAFE | bool | false | enabling this option will turn off thread safety locks in the FFmpeg backend (use only if you are sure FFmpeg is built with threading support, tested on Linux) |
@ -286,7 +285,7 @@ Some external dependencies can be detached into a dynamic library, which will be
| OPENCV_VIDEOIO_MFX_BITRATE_DIVISOR | num | 300 | this option allows to tune encoding bitrate (video quality/size) | | OPENCV_VIDEOIO_MFX_BITRATE_DIVISOR | num | 300 | this option allows to tune encoding bitrate (video quality/size) |
| OPENCV_VIDEOIO_MFX_WRITER_TIMEOUT | num | 1 | timeout for encoding operation (in seconds) | | OPENCV_VIDEOIO_MFX_WRITER_TIMEOUT | num | 1 | timeout for encoding operation (in seconds) |
| OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS | bool | true | allow HW-accelerated transformations (DXVA) in MediaFoundation processing graph (may slow down camera probing process) | | OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS | bool | true | allow HW-accelerated transformations (DXVA) in MediaFoundation processing graph (may slow down camera probing process) |
| OPENCV_DSHOW_DEBUG | non-null | | enable verbose logging in the DShow backend | | OPENCV_DSHOW_DEBUG | bool | false | enable verbose logging in the DShow backend |
| OPENCV_DSHOW_SAVEGRAPH_FILENAME | file path | | enable processing graph tump in the DShow backend | | OPENCV_DSHOW_SAVEGRAPH_FILENAME | file path | | enable processing graph tump in the DShow backend |
| OPENCV_VIDEOIO_V4L_RANGE_NORMALIZED | bool | false | use (0, 1) range for properties (V4L) | | OPENCV_VIDEOIO_V4L_RANGE_NORMALIZED | bool | false | use (0, 1) range for properties (V4L) |
| OPENCV_VIDEOIO_V4L_SELECT_TIMEOUT | num | 10 | timeout for select call (in seconds) (V4L) | | OPENCV_VIDEOIO_V4L_SELECT_TIMEOUT | num | 10 | timeout for select call (in seconds) (V4L) |
@ -297,7 +296,7 @@ Some external dependencies can be detached into a dynamic library, which will be
### videoio tests ### videoio tests
| name | type | default | description | | name | type | default | description |
|------|------|---------|-------------| |------|------|---------|-------------|
| OPENCV_TEST_VIDEOIO_BACKEND_REQUIRE_FFMPEG | | | test app will exit if no FFmpeg backend is available | | OPENCV_TEST_VIDEOIO_BACKEND_REQUIRE_FFMPEG | bool | false | test app will exit if no FFmpeg backend is available |
| OPENCV_TEST_V4L2_VIVID_DEVICE | file path | | path to VIVID virtual camera device for V4L2 test (e.g. `/dev/video5`) | | OPENCV_TEST_V4L2_VIVID_DEVICE | file path | | path to VIVID virtual camera device for V4L2 test (e.g. `/dev/video5`) |
| OPENCV_TEST_PERF_CAMERA_LIST | paths | | cameras to use in performance test (waitAny_V4L test) | | OPENCV_TEST_PERF_CAMERA_LIST | paths | | cameras to use in performance test (waitAny_V4L test) |
| OPENCV_TEST_CAMERA_%d_FPS | num | | fps to set for N-th camera (0-based index) (waitAny_V4L test) | | OPENCV_TEST_CAMERA_%d_FPS | num | | fps to set for N-th camera (0-based index) (waitAny_V4L test) |
@ -327,7 +326,7 @@ Some external dependencies can be detached into a dynamic library, which will be
| name | type | default | description | | name | type | default | description |
|------|------|---------|-------------| |------|------|---------|-------------|
| OPENCV_LEGACY_WAITKEY | non-null | | switch `waitKey` return result (default behavior: `return code & 0xff` (or -1), legacy behavior: `return code`) | | OPENCV_LEGACY_WAITKEY | bool | false | switch `waitKey` return result (default behavior: `return code & 0xff` (or -1), legacy behavior: `return code`) |
| $XDG_RUNTIME_DIR | | | Wayland backend specific - create shared memory-mapped file for interprocess communication (named `opencv-shared-??????`) | | $XDG_RUNTIME_DIR | | | Wayland backend specific - create shared memory-mapped file for interprocess communication (named `opencv-shared-??????`) |
| OPENCV_HIGHGUI_FB_MODE | string | `FB` | Selects output mode for the framebuffer backend (`FB` - regular frambuffer, `EMU` - emulation, perform internal checks but does nothing, `XVFB` - compatible with _xvfb_ virtual frambuffer) | | OPENCV_HIGHGUI_FB_MODE | string | `FB` | Selects output mode for the framebuffer backend (`FB` - regular frambuffer, `EMU` - emulation, perform internal checks but does nothing, `XVFB` - compatible with _xvfb_ virtual frambuffer) |
| OPENCV_HIGHGUI_FB_DEVICE | file path | | Path to frambuffer device to use (will be checked first) | | OPENCV_HIGHGUI_FB_DEVICE | file path | | Path to frambuffer device to use (will be checked first) |

View File

@ -182,6 +182,10 @@ if(OPENCV_DISABLE_THREAD_SUPPORT)
ocv_target_compile_definitions(${the_module} PUBLIC "OPENCV_DISABLE_THREAD_SUPPORT=1") ocv_target_compile_definitions(${the_module} PUBLIC "OPENCV_DISABLE_THREAD_SUPPORT=1")
endif() endif()
if(OPENCV_DISABLE_ENV_SUPPORT)
ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/system.cpp "NO_GETENV")
endif()
if(OPENCV_SEMIHOSTING) if(OPENCV_SEMIHOSTING)
ocv_target_compile_definitions(${the_module} PRIVATE "-DOPENCV_SEMIHOSTING") ocv_target_compile_definitions(${the_module} PRIVATE "-DOPENCV_SEMIHOSTING")
endif(OPENCV_SEMIHOSTING) endif(OPENCV_SEMIHOSTING)

View File

@ -12,9 +12,9 @@
namespace cv { namespace utils { namespace cv { namespace utils {
typedef std::vector<std::string> Paths; typedef std::vector<std::string> Paths;
CV_EXPORTS bool getConfigurationParameterBool(const char* name, bool defaultValue); CV_EXPORTS bool getConfigurationParameterBool(const char* name, bool defaultValue = false);
CV_EXPORTS size_t getConfigurationParameterSizeT(const char* name, size_t defaultValue); CV_EXPORTS size_t getConfigurationParameterSizeT(const char* name, size_t defaultValue = 0);
CV_EXPORTS cv::String getConfigurationParameterString(const char* name, const char* defaultValue); CV_EXPORTS std::string getConfigurationParameterString(const char* name, const std::string & defaultValue = std::string());
CV_EXPORTS Paths getConfigurationParameterPaths(const char* name, const Paths &defaultValue = Paths()); CV_EXPORTS Paths getConfigurationParameterPaths(const char* name, const Paths &defaultValue = Paths());
}} // namespace }} // namespace

View File

@ -1170,10 +1170,10 @@ bool haveOpenCL()
if (!g_isOpenCLInitialized) if (!g_isOpenCLInitialized)
{ {
CV_TRACE_REGION("Init_OpenCL_Runtime"); CV_TRACE_REGION("Init_OpenCL_Runtime");
const char* envPath = getenv("OPENCV_OPENCL_RUNTIME"); std::string envPath = utils::getConfigurationParameterString("OPENCV_OPENCL_RUNTIME");
if (envPath) if (!envPath.empty())
{ {
if (cv::String(envPath) == "disabled") if (envPath == "disabled")
{ {
g_isOpenCLAvailable = false; g_isOpenCLAvailable = false;
g_isOpenCLInitialized = true; g_isOpenCLInitialized = true;
@ -2119,24 +2119,18 @@ static bool parseOpenCLDeviceConfiguration(const std::string& configurationStr,
return true; return true;
} }
#if defined WINRT || defined _WIN32_WCE static cl_device_id selectOpenCLDevice(const std::string & configuration_ = std::string())
static cl_device_id selectOpenCLDevice(const char* configuration = NULL)
{
CV_UNUSED(configuration)
return NULL;
}
#else
static cl_device_id selectOpenCLDevice(const char* configuration = NULL)
{ {
std::string platform, deviceName; std::string platform, deviceName;
std::vector<std::string> deviceTypes; std::vector<std::string> deviceTypes;
if (!configuration) std::string configuration(configuration_);
configuration = getenv("OPENCV_OPENCL_DEVICE"); if (configuration.empty())
configuration = utils::getConfigurationParameterString("OPENCV_OPENCL_DEVICE");
if (configuration && if (!configuration.empty() &&
(strcmp(configuration, "disabled") == 0 || (configuration == "disabled" ||
!parseOpenCLDeviceConfiguration(std::string(configuration), platform, deviceTypes, deviceName) !parseOpenCLDeviceConfiguration(configuration, platform, deviceTypes, deviceName)
)) ))
return NULL; return NULL;
@ -2204,7 +2198,7 @@ static cl_device_id selectOpenCLDevice(const char* configuration = NULL)
if (!isID) if (!isID)
{ {
deviceTypes.push_back("GPU"); deviceTypes.push_back("GPU");
if (configuration) if (!configuration.empty())
deviceTypes.push_back("CPU"); deviceTypes.push_back("CPU");
} }
else else
@ -2272,7 +2266,7 @@ static cl_device_id selectOpenCLDevice(const char* configuration = NULL)
} }
not_found: not_found:
if (!configuration) if (configuration.empty())
return NULL; // suppress messages on stderr return NULL; // suppress messages on stderr
std::ostringstream msg; std::ostringstream msg;
@ -2287,7 +2281,6 @@ not_found:
CV_LOG_ERROR(NULL, msg.str()); CV_LOG_ERROR(NULL, msg.str());
return NULL; return NULL;
} }
#endif
#ifdef HAVE_OPENCL_SVM #ifdef HAVE_OPENCL_SVM
namespace svm { namespace svm {
@ -2340,12 +2333,12 @@ static unsigned int getSVMCapabilitiesMask()
static unsigned int mask = 0; static unsigned int mask = 0;
if (!initialized) if (!initialized)
{ {
const char* envValue = getenv("OPENCV_OPENCL_SVM_CAPABILITIES_MASK"); const std::string envValue = utils::getConfigurationParameterString("OPENCV_OPENCL_SVM_CAPABILITIES_MASK");
if (envValue == NULL) if (envValue.empty())
{ {
return ~0U; // all bits 1 return ~0U; // all bits 1
} }
mask = atoi(envValue); mask = atoi(envValue.c_str());
initialized = true; initialized = true;
} }
return mask; return mask;
@ -2482,8 +2475,8 @@ public:
std::string configuration = configuration_; std::string configuration = configuration_;
if (configuration_.empty()) if (configuration_.empty())
{ {
const char* c = getenv("OPENCV_OPENCL_DEVICE"); const std::string c = utils::getConfigurationParameterString("OPENCV_OPENCL_DEVICE");
if (c) if (!c.empty())
configuration = c; configuration = c;
} }
Impl* impl = findContext(configuration); Impl* impl = findContext(configuration);
@ -2494,7 +2487,7 @@ public:
return impl; return impl;
} }
cl_device_id d = selectOpenCLDevice(configuration.empty() ? NULL : configuration.c_str()); cl_device_id d = selectOpenCLDevice(configuration);
if (d == NULL) if (d == NULL)
return NULL; return NULL;

View File

@ -44,6 +44,7 @@
#if defined(HAVE_OPENCL) #if defined(HAVE_OPENCL)
#include "opencv2/core.hpp" // CV_Error #include "opencv2/core.hpp" // CV_Error
#include "opencv2/core/utils/configuration.private.hpp"
#if defined(HAVE_OPENCL_STATIC) #if defined(HAVE_OPENCL_STATIC)
#if defined __APPLE__ #if defined __APPLE__
@ -64,18 +65,14 @@ CV_SUPPRESS_DEPRECATED_END
#define ERROR_MSG_CANT_LOAD "Failed to load OpenCL runtime\n" #define ERROR_MSG_CANT_LOAD "Failed to load OpenCL runtime\n"
#define ERROR_MSG_INVALID_VERSION "Failed to load OpenCL runtime (expected version 1.1+)\n" #define ERROR_MSG_INVALID_VERSION "Failed to load OpenCL runtime (expected version 1.1+)\n"
static const char* getRuntimePath(const char* defaultPath) static std::string getRuntimePath(const std::string & defaultPath)
{ {
const char* envPath = getenv("OPENCV_OPENCL_RUNTIME"); const std::string res = cv::utils::getConfigurationParameterString(
if (envPath) "OPENCV_OPENCL_RUNTIME", defaultPath);
{ if (res == "disabled")
static const char disabled_str[] = "disabled"; return std::string();
if ((strlen(envPath) == sizeof(disabled_str) - 1) && else
(memcmp(envPath, disabled_str, sizeof(disabled_str) - 1) == 0)) return res;
return NULL;
return envPath;
}
return defaultPath;
} }
#if defined(__APPLE__) #if defined(__APPLE__)
@ -91,9 +88,9 @@ static void* AppleCLGetProcAddress(const char* name)
if (!initialized) if (!initialized)
{ {
const char* defaultPath = "/System/Library/Frameworks/OpenCL.framework/Versions/Current/OpenCL"; const char* defaultPath = "/System/Library/Frameworks/OpenCL.framework/Versions/Current/OpenCL";
const char* path = getRuntimePath(defaultPath); std::string path = getRuntimePath(defaultPath);
if (path) if (!path.empty())
handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL);
if (handle == NULL) if (handle == NULL)
{ {
if (path != NULL && path != defaultPath) if (path != NULL && path != defaultPath)
@ -129,13 +126,13 @@ static void* WinGetProcAddress(const char* name)
handle = GetModuleHandleA("OpenCL.dll"); handle = GetModuleHandleA("OpenCL.dll");
if (!handle) if (!handle)
{ {
const char* defaultPath = "OpenCL.dll"; const std::string defaultPath = "OpenCL.dll";
const char* path = getRuntimePath(defaultPath); const std::string path = getRuntimePath(defaultPath);
if (path) if (!path.empty())
handle = LoadLibraryA(path); handle = LoadLibraryA(path.c_str());
if (!handle) if (!handle)
{ {
if (path != NULL && path != defaultPath) if (!path.empty() && path != defaultPath)
fprintf(stderr, ERROR_MSG_CANT_LOAD); fprintf(stderr, ERROR_MSG_CANT_LOAD);
} }
else if (GetProcAddress(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL) else if (GetProcAddress(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL)
@ -205,8 +202,8 @@ static void* GetProcAddress(const char* name)
bool foundOpenCL = false; bool foundOpenCL = false;
for (unsigned int i = 0; i < (sizeof(defaultAndroidPaths)/sizeof(char*)); i++) for (unsigned int i = 0; i < (sizeof(defaultAndroidPaths)/sizeof(char*)); i++)
{ {
const char* path = (i==0) ? getRuntimePath(defaultAndroidPaths[i]) : defaultAndroidPaths[i]; const std::string path = (i==0) ? getRuntimePath(defaultAndroidPaths[i]) : defaultAndroidPaths[i];
if (path) { if (!path.empty()) {
handle = GetHandle(path); handle = GetHandle(path);
if (handle) { if (handle) {
foundOpenCL = true; foundOpenCL = true;
@ -236,10 +233,10 @@ static void* GetProcAddress(const char* name)
if (!initialized) if (!initialized)
{ {
const char* defaultPath = "libOpenCL.so"; const char* defaultPath = "libOpenCL.so";
const char* path = getRuntimePath(defaultPath); const std::string path = getRuntimePath(defaultPath);
if (path) if (!path.empty())
{ {
handle = GetHandle(path); handle = GetHandle(path.c_str());
if (!handle) if (!handle)
{ {
if (path == defaultPath) if (path == defaultPath)

View File

@ -111,7 +111,7 @@ protected:
bool readPrioritySettings() bool readPrioritySettings()
{ {
bool hasChanges = false; bool hasChanges = false;
cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_PARALLEL_PRIORITY_LIST", NULL); cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_PARALLEL_PRIORITY_LIST");
if (prioritized_backends.empty()) if (prioritized_backends.empty())
return hasChanges; return hasChanges;
CV_LOG_INFO(NULL, "core(parallel): Configured priority list (OPENCV_PARALLEL_PRIORITY_LIST): " << prioritized_backends); CV_LOG_INFO(NULL, "core(parallel): Configured priority list (OPENCV_PARALLEL_PRIORITY_LIST): " << prioritized_backends);

View File

@ -450,13 +450,11 @@ struct HWFeatures
void initialize(void) void initialize(void)
{ {
#ifndef NO_GETENV if (utils::getConfigurationParameterBool("OPENCV_DUMP_CONFIG"))
if (getenv("OPENCV_DUMP_CONFIG"))
{ {
fprintf(stderr, "\nOpenCV build configuration is:\n%s\n", fprintf(stderr, "\nOpenCV build configuration is:\n%s\n",
cv::getBuildInformation().c_str()); cv::getBuildInformation().c_str());
} }
#endif
initializeNames(); initializeNames();
@ -731,12 +729,10 @@ struct HWFeatures
#endif #endif
bool skip_baseline_check = false; bool skip_baseline_check = false;
#ifndef NO_GETENV if (utils::getConfigurationParameterBool("OPENCV_SKIP_CPU_BASELINE_CHECK"))
if (getenv("OPENCV_SKIP_CPU_BASELINE_CHECK"))
{ {
skip_baseline_check = true; skip_baseline_check = true;
} }
#endif
int baseline_features[] = { CV_CPU_BASELINE_FEATURES }; int baseline_features[] = { CV_CPU_BASELINE_FEATURES };
if (!checkFeatures(baseline_features, sizeof(baseline_features) / sizeof(baseline_features[0])) if (!checkFeatures(baseline_features, sizeof(baseline_features) / sizeof(baseline_features[0]))
&& !skip_baseline_check) && !skip_baseline_check)
@ -786,15 +782,10 @@ struct HWFeatures
void readSettings(const int* baseline_features, int baseline_count) void readSettings(const int* baseline_features, int baseline_count)
{ {
bool dump = true; bool dump = true;
const char* disabled_features = std::string disabled_features = utils::getConfigurationParameterString("OPENCV_CPU_DISABLE");
#ifdef NO_GETENV if (!disabled_features.empty())
NULL;
#else
getenv("OPENCV_CPU_DISABLE");
#endif
if (disabled_features && disabled_features[0] != 0)
{ {
const char* start = disabled_features; const char* start = disabled_features.c_str();
for (;;) for (;;)
{ {
while (start[0] != 0 && isSymbolSeparator(start[0])) while (start[0] != 0 && isSymbolSeparator(start[0]))
@ -1080,20 +1071,19 @@ String tempfile( const char* suffix )
{ {
#if OPENCV_HAVE_FILESYSTEM_SUPPORT #if OPENCV_HAVE_FILESYSTEM_SUPPORT
String fname; String fname;
#ifndef NO_GETENV
const char *temp_dir = getenv("OPENCV_TEMP_PATH"); std::string temp_dir = utils::getConfigurationParameterString("OPENCV_TEMP_PATH");
#endif
#if defined _WIN32 #if defined _WIN32
#ifdef WINRT #ifdef WINRT
RoInitialize(RO_INIT_MULTITHREADED); RoInitialize(RO_INIT_MULTITHREADED);
std::wstring temp_dir = GetTempPathWinRT(); std::wstring temp_dir_rt = GetTempPathWinRT();
std::wstring temp_file = GetTempFileNameWinRT(L"ocv"); std::wstring temp_file = GetTempFileNameWinRT(L"ocv");
if (temp_file.empty()) if (temp_file.empty())
return String(); return String();
temp_file = temp_dir.append(std::wstring(L"\\")).append(temp_file); temp_file = temp_dir_rt.append(std::wstring(L"\\")).append(temp_file);
DeleteFileW(temp_file.c_str()); DeleteFileW(temp_file.c_str());
char aname[MAX_PATH]; char aname[MAX_PATH];
@ -1103,12 +1093,12 @@ String tempfile( const char* suffix )
RoUninitialize(); RoUninitialize();
#elif defined(_WIN32_WCE) #elif defined(_WIN32_WCE)
const auto kMaxPathSize = MAX_PATH+1; const auto kMaxPathSize = MAX_PATH+1;
wchar_t temp_dir[kMaxPathSize] = {0}; wchar_t temp_dir_ce[kMaxPathSize] = {0};
wchar_t temp_file[kMaxPathSize] = {0}; wchar_t temp_file[kMaxPathSize] = {0};
::GetTempPathW(kMaxPathSize, temp_dir); ::GetTempPathW(kMaxPathSize, temp_dir_ce);
if(0 != ::GetTempFileNameW(temp_dir, L"ocv", 0, temp_file)) { if(0 != ::GetTempFileNameW(temp_dir_ce, L"ocv", 0, temp_file)) {
DeleteFileW(temp_file); DeleteFileW(temp_file);
char aname[MAX_PATH]; char aname[MAX_PATH];
size_t copied = wcstombs(aname, temp_file, MAX_PATH); size_t copied = wcstombs(aname, temp_file, MAX_PATH);
@ -1119,12 +1109,12 @@ String tempfile( const char* suffix )
char temp_dir2[MAX_PATH] = { 0 }; char temp_dir2[MAX_PATH] = { 0 };
char temp_file[MAX_PATH] = { 0 }; char temp_file[MAX_PATH] = { 0 };
if (temp_dir == 0 || temp_dir[0] == 0) if (temp_dir.empty())
{ {
::GetTempPathA(sizeof(temp_dir2), temp_dir2); ::GetTempPathA(sizeof(temp_dir2), temp_dir2);
temp_dir = temp_dir2; temp_dir = std::string(temp_dir2);
} }
if(0 == ::GetTempFileNameA(temp_dir, "ocv", 0, temp_file)) if(0 == ::GetTempFileNameA(temp_dir.c_str(), "ocv", 0, temp_file))
return String(); return String();
DeleteFileA(temp_file); DeleteFileA(temp_file);
@ -1139,7 +1129,7 @@ String tempfile( const char* suffix )
char defaultTemplate[] = "/tmp/__opencv_temp.XXXXXX"; char defaultTemplate[] = "/tmp/__opencv_temp.XXXXXX";
# endif # endif
if (temp_dir == 0 || temp_dir[0] == 0) if (temp_dir.empty())
fname = defaultTemplate; fname = defaultTemplate;
else else
{ {
@ -2289,9 +2279,9 @@ size_t utils::getConfigurationParameterSizeT(const char* name, size_t defaultVal
return read<size_t>(name, defaultValue); return read<size_t>(name, defaultValue);
} }
cv::String utils::getConfigurationParameterString(const char* name, const char* defaultValue) std::string utils::getConfigurationParameterString(const char* name, const std::string & defaultValue)
{ {
return read<cv::String>(name, defaultValue ? cv::String(defaultValue) : cv::String()); return read<cv::String>(name, defaultValue);
} }
utils::Paths utils::getConfigurationParameterPaths(const char* name, const utils::Paths &defaultValue) utils::Paths utils::getConfigurationParameterPaths(const char* name, const utils::Paths &defaultValue)
@ -2588,11 +2578,8 @@ public:
} }
ippFeatures = cpuFeatures; ippFeatures = cpuFeatures;
const char* pIppEnv = getenv("OPENCV_IPP"); std::string env = utils::getConfigurationParameterString("OPENCV_IPP");
cv::String env; if(!env.empty())
if(pIppEnv != NULL)
env = pIppEnv;
if(env.size())
{ {
#if IPP_VERSION_X100 >= 201900 #if IPP_VERSION_X100 >= 201900
const Ipp64u minorFeatures = ippCPUID_MOVBE|ippCPUID_AES|ippCPUID_CLMUL|ippCPUID_ABR|ippCPUID_RDRAND|ippCPUID_F16C| const Ipp64u minorFeatures = ippCPUID_MOVBE|ippCPUID_AES|ippCPUID_CLMUL|ippCPUID_ABR|ippCPUID_RDRAND|ippCPUID_F16C|

View File

@ -60,7 +60,7 @@ static std::vector<cv::String>& _getDataSearchSubDirectory()
CV_EXPORTS void addDataSearchPath(const cv::String& path) CV_EXPORTS void addDataSearchPath(const cv::String& path)
{ {
if (utils::fs::isDirectory(path)) if (!path.empty() && utils::fs::isDirectory(path))
_getDataSearchPath().push_back(path); _getDataSearchPath().push_back(path);
} }
CV_EXPORTS void addDataSearchSubDirectory(const cv::String& subdir) CV_EXPORTS void addDataSearchSubDirectory(const cv::String& subdir)

View File

@ -447,8 +447,8 @@ cv::String getCacheDirectory(const char* sub_directory_name, const char* configu
#elif defined __ANDROID__ #elif defined __ANDROID__
// no defaults // no defaults
#elif defined __APPLE__ #elif defined __APPLE__
const char* tmpdir_env = getenv("TMPDIR"); const std::string tmpdir_env = utils::getConfigurationParameterString("TMPDIR");
if (tmpdir_env && utils::fs::isDirectory(tmpdir_env)) if (!tmpdir_env.empty() && utils::fs::isDirectory(tmpdir_env))
{ {
default_cache_path = tmpdir_env; default_cache_path = tmpdir_env;
} }
@ -461,16 +461,16 @@ cv::String getCacheDirectory(const char* sub_directory_name, const char* configu
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
if (default_cache_path.empty()) if (default_cache_path.empty())
{ {
const char* xdg_cache_env = getenv("XDG_CACHE_HOME"); const std::string xdg_cache_env = utils::getConfigurationParameterString("XDG_CACHE_HOME");
if (xdg_cache_env && xdg_cache_env[0] && utils::fs::isDirectory(xdg_cache_env)) if (!xdg_cache_env.empty() && utils::fs::isDirectory(xdg_cache_env))
{ {
default_cache_path = xdg_cache_env; default_cache_path = xdg_cache_env;
} }
} }
if (default_cache_path.empty()) if (default_cache_path.empty())
{ {
const char* home_env = getenv("HOME"); const std::string home_env = utils::getConfigurationParameterString("HOME");
if (home_env && home_env[0] && utils::fs::isDirectory(home_env)) if (!home_env.empty() && utils::fs::isDirectory(home_env))
{ {
cv::String home_path = home_env; cv::String home_path = home_env;
cv::String home_cache_path = utils::fs::join(home_path, ".cache/"); cv::String home_cache_path = utils::fs::join(home_path, ".cache/");

View File

@ -7,6 +7,7 @@
// //
#include "opencv2/core/utils/plugin_loader.private.hpp" // DynamicLib #include "opencv2/core/utils/plugin_loader.private.hpp" // DynamicLib
#include "opencv2/core/utils/configuration.private.hpp"
namespace cv { namespace detail { namespace cv { namespace detail {
@ -47,8 +48,8 @@ static FN_vaGetImage fn_vaGetImage = NULL;
static std::shared_ptr<cv::plugin::impl::DynamicLib> loadLibVA() static std::shared_ptr<cv::plugin::impl::DynamicLib> loadLibVA()
{ {
std::shared_ptr<cv::plugin::impl::DynamicLib> lib; std::shared_ptr<cv::plugin::impl::DynamicLib> lib;
const char* envPath = getenv("OPENCV_LIBVA_RUNTIME"); const std::string envPath = utils::getConfigurationParameterString("OPENCV_LIBVA_RUNTIME");
if (envPath) if (!envPath.empty())
{ {
lib = std::make_shared<cv::plugin::impl::DynamicLib>(envPath); lib = std::make_shared<cv::plugin::impl::DynamicLib>(envPath);
return lib; return lib;

View File

@ -1,16 +1,7 @@
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
static const char* extraTestDataPath =
#ifdef WINRT
NULL;
#else
getenv("OPENCV_DNN_TEST_DATA_PATH");
#endif
#if defined(HAVE_HPX) #if defined(HAVE_HPX)
#include <hpx/hpx_main.hpp> #include <hpx/hpx_main.hpp>
#endif #endif
CV_PERF_TEST_MAIN(dnn, CV_PERF_TEST_MAIN(dnn, cvtest::addDataSearchEnv("OPENCV_DNN_TEST_DATA_PATH"))
extraTestDataPath ? (void)cvtest::addDataSearchPath(extraTestDataPath) : (void)0
)

View File

@ -47,6 +47,7 @@
#endif #endif
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
#include "opencv2/core/utils/configuration.private.hpp"
#ifndef CV_OCL4DNN #ifndef CV_OCL4DNN
#define CV_OCL4DNN 0 #define CV_OCL4DNN 0

View File

@ -115,21 +115,12 @@ bool loadVulkanLibrary()
if (handle != nullptr) if (handle != nullptr)
return true; return true;
const char* path; const std::string path = cv::utils::getConfigurationParameterString("OPENCV_VULKAN_RUNTIME", DEFAULT_VK_LIBRARY_PATH);
const char* envPath = getenv("OPENCV_VULKAN_RUNTIME");
if (envPath)
{
path = envPath;
}
else
{
path = DEFAULT_VK_LIBRARY_PATH;
}
handle = LOAD_VK_LIBRARY(path); handle = LOAD_VK_LIBRARY(path.c_str());
if( handle == nullptr ) if( handle == nullptr )
{ {
fprintf(stderr, "Could not load Vulkan library: %s!\n", path); fprintf(stderr, "Could not load Vulkan library: %s!\n", path.c_str());
fprintf(stderr, "Please download the Vulkan SDK and set the environment variable of OPENCV_VULKAN_RUNTIME according " fprintf(stderr, "Please download the Vulkan SDK and set the environment variable of OPENCV_VULKAN_RUNTIME according "
"to your system environment.\n"); "to your system environment.\n");
fprintf(stderr, "For M1 Mac and IOS, we use MoltenVK to map the Vulkan code to native apple Metal code.\n"); fprintf(stderr, "For M1 Mac and IOS, we use MoltenVK to map the Vulkan code to native apple Metal code.\n");

View File

@ -437,14 +437,7 @@ bool validateVPUType()
void initDNNTests() void initDNNTests()
{ {
const char* extraTestDataPath = cvtest::addDataSearchEnv("OPENCV_DNN_TEST_DATA_PATH");
#ifdef WINRT
NULL;
#else
getenv("OPENCV_DNN_TEST_DATA_PATH");
#endif
if (extraTestDataPath)
cvtest::addDataSearchPath(extraTestDataPath);
registerGlobalSkipTag( registerGlobalSkipTag(
CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND, CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND,

View File

@ -40,15 +40,11 @@ static void initDLDTDataPath()
if (!initialized) if (!initialized)
{ {
#if INF_ENGINE_RELEASE <= 2018050000 #if INF_ENGINE_RELEASE <= 2018050000
const char* dldtTestDataPath = getenv("INTEL_CVSDK_DIR"); cvtest::addDataSearchEnv("INTEL_CVSDK_DIR");
if (dldtTestDataPath)
cvtest::addDataSearchPath(dldtTestDataPath);
#else #else
const char* omzDataPath = getenv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH"); cvtest::addDataSearchEnv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH");
if (omzDataPath) const std::string dnnDataPath = cv::utils::getConfigurationParameterString("OPENCV_DNN_TEST_DATA_PATH");
cvtest::addDataSearchPath(omzDataPath); if (!dnnDataPath.empty())
const char* dnnDataPath = getenv("OPENCV_DNN_TEST_DATA_PATH");
if (dnnDataPath)
cvtest::addDataSearchPath(std::string(dnnDataPath) + "/omz_intel_models"); cvtest::addDataSearchPath(std::string(dnnDataPath) + "/omz_intel_models");
#endif #endif
initialized = true; initialized = true;

View File

@ -45,6 +45,7 @@
#include "opencv2/ts/ts_perf.hpp" #include "opencv2/ts/ts_perf.hpp"
#include "opencv2/core/utility.hpp" #include "opencv2/core/utility.hpp"
#include "opencv2/core/ocl.hpp" #include "opencv2/core/ocl.hpp"
#include "opencv2/core/utils/configuration.private.hpp"
#include "opencv2/dnn.hpp" #include "opencv2/dnn.hpp"
#include "test_common.hpp" #include "test_common.hpp"

View File

@ -99,9 +99,9 @@ namespace
auto dump_info = cv::gapi::getCompileArg<cv::graph_dump_path>(args); auto dump_info = cv::gapi::getCompileArg<cv::graph_dump_path>(args);
if (!dump_info.has_value()) if (!dump_info.has_value())
{ {
const char* path = std::getenv("GRAPH_DUMP_PATH"); const std::string path = cv::utils::getConfigurationParameterString("GRAPH_DUMP_PATH");
return path return !path.empty()
? cv::util::make_optional(std::string(path)) ? cv::util::make_optional(path)
: cv::util::optional<std::string>(); : cv::util::optional<std::string>();
} }
else else

View File

@ -10,6 +10,7 @@
#if !defined(GAPI_STANDALONE) #if !defined(GAPI_STANDALONE)
# include <opencv2/core.hpp> # include <opencv2/core.hpp>
# include <opencv2/core/utils/configuration.private.hpp>
# include <opencv2/imgproc.hpp> # include <opencv2/imgproc.hpp>
# include <opencv2/gapi/core.hpp> # include <opencv2/gapi/core.hpp>
# include <opencv2/gapi/imgproc.hpp> # include <opencv2/gapi/imgproc.hpp>

View File

@ -101,22 +101,18 @@ public:
// FIXME: taken from DNN module // FIXME: taken from DNN module
static void initDLDTDataPath() static void initDLDTDataPath()
{ {
#ifndef WINRT
static bool initialized = false; static bool initialized = false;
if (!initialized) if (!initialized)
{ {
const char* omzDataPath = getenv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH"); cvtest::addDataSearchEnv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH");
if (omzDataPath) const std::string dnnDataPath = cv::utils::getConfigurationParameterString("OPENCV_DNN_TEST_DATA_PATH");
cvtest::addDataSearchPath(omzDataPath); if (!dnnDataPath.empty()) {
const char* dnnDataPath = getenv("OPENCV_DNN_TEST_DATA_PATH");
if (dnnDataPath) {
// Add the dnnDataPath itself - G-API is using some images there directly // Add the dnnDataPath itself - G-API is using some images there directly
cvtest::addDataSearchPath(dnnDataPath); cvtest::addDataSearchPath(dnnDataPath);
cvtest::addDataSearchPath(dnnDataPath + std::string("/omz_intel_models")); cvtest::addDataSearchPath(dnnDataPath + std::string("/omz_intel_models"));
} }
initialized = true; initialized = true;
} }
#endif // WINRT
} }
#if INF_ENGINE_RELEASE >= 2020010000 #if INF_ENGINE_RELEASE >= 2020010000

View File

@ -58,10 +58,7 @@ public:
}; };
struct ONNXInitPath { struct ONNXInitPath {
ONNXInitPath() { ONNXInitPath() {
const char* env_path = getenv("OPENCV_GAPI_ONNX_MODEL_PATH"); cvtest::addDataSearchEnv("OPENCV_GAPI_ONNX_MODEL_PATH");
if (env_path) {
cvtest::addDataSearchPath(env_path);
}
} }
}; };
static ONNXInitPath g_init_path; static ONNXInitPath g_init_path;

View File

@ -25,11 +25,9 @@ void initDLDTDataPath()
static bool initialized = false; static bool initialized = false;
if (!initialized) if (!initialized)
{ {
const char* omzDataPath = getenv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH"); cvtest::addDataSearchEnv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH");
if (omzDataPath) const std::string dnnDataPath = cv::utils::getConfigurationParameterString("OPENCV_DNN_TEST_DATA_PATH");
cvtest::addDataSearchPath(omzDataPath); if (!dnnDataPath.empty()) {
const char* dnnDataPath = getenv("OPENCV_DNN_TEST_DATA_PATH");
if (dnnDataPath) {
// Add the dnnDataPath itself - G-API is using some images there directly // Add the dnnDataPath itself - G-API is using some images there directly
cvtest::addDataSearchPath(dnnDataPath); cvtest::addDataSearchPath(dnnDataPath);
cvtest::addDataSearchPath(dnnDataPath + std::string("/omz_intel_models")); cvtest::addDataSearchPath(dnnDataPath + std::string("/omz_intel_models"));

View File

@ -16,6 +16,8 @@
#include <opencv2/ts.hpp> #include <opencv2/ts.hpp>
#include <opencv2/core/utils/configuration.private.hpp>
#include <opencv2/gapi.hpp> #include <opencv2/gapi.hpp>
#include <opencv2/gapi/core.hpp> #include <opencv2/gapi/core.hpp>
#include <opencv2/gapi/imgproc.hpp> #include <opencv2/gapi/imgproc.hpp>

View File

@ -54,6 +54,7 @@
#include "opencv2/core/utility.hpp" #include "opencv2/core/utility.hpp"
#if defined(__OPENCV_BUILD) #if defined(__OPENCV_BUILD)
#include "opencv2/core/private.hpp" #include "opencv2/core/private.hpp"
#include "opencv2/core/utils/configuration.private.hpp"
#endif #endif
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"

View File

@ -133,7 +133,7 @@ protected:
bool readPrioritySettings() bool readPrioritySettings()
{ {
bool hasChanges = false; bool hasChanges = false;
cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_UI_PRIORITY_LIST", NULL); cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_UI_PRIORITY_LIST");
if (prioritized_backends.empty()) if (prioritized_backends.empty())
return hasChanges; return hasChanges;
CV_LOG_INFO(NULL, "UI: Configured priority list (OPENCV_UI_PRIORITY_LIST): " << prioritized_backends); CV_LOG_INFO(NULL, "UI: Configured priority list (OPENCV_UI_PRIORITY_LIST): " << prioritized_backends);

View File

@ -662,7 +662,7 @@ int cv::waitKey(int delay)
static int use_legacy = -1; static int use_legacy = -1;
if (use_legacy < 0) if (use_legacy < 0)
{ {
use_legacy = getenv("OPENCV_LEGACY_WAITKEY") != NULL ? 1 : 0; use_legacy = utils::getConfigurationParameterBool("OPENCV_LEGACY_WAITKEY");
} }
if (use_legacy > 0) if (use_legacy > 0)
return code; return code;

View File

@ -1378,7 +1378,7 @@ int cv_wl_buffer::create_tmpfile(std::string const &tmpname) {
} }
int cv_wl_buffer::create_anonymous_file(off_t size) { int cv_wl_buffer::create_anonymous_file(off_t size) {
auto path = getenv("XDG_RUNTIME_DIR") + std::string("/opencv-shared-XXXXXX"); auto path = cv::utils::getConfigurationParameterString("XDG_RUNTIME_DIR") + std::string("/opencv-shared-XXXXXX");
int fd = create_tmpfile(path); int fd = create_tmpfile(path);
int ret = posix_fallocate(fd, 0, size); int ret = posix_fallocate(fd, 0, size);

View File

@ -11,14 +11,7 @@ static
void initTests() void initTests()
{ {
#ifdef HAVE_OPENCV_DNN #ifdef HAVE_OPENCV_DNN
const char* extraTestDataPath = cvtest::addDataSearchEnv("OPENCV_DNN_TEST_DATA_PATH");
#ifdef WINRT
NULL;
#else
getenv("OPENCV_DNN_TEST_DATA_PATH");
#endif
if (extraTestDataPath)
cvtest::addDataSearchPath(extraTestDataPath);
#endif // HAVE_OPENCV_DNN #endif // HAVE_OPENCV_DNN
} }

View File

@ -754,6 +754,7 @@ void smoothBorder(Mat& img, const Scalar& color, int delta = 3);
// Utility functions // Utility functions
void addDataSearchPath(const std::string& path); void addDataSearchPath(const std::string& path);
void addDataSearchEnv(const std::string& env_name);
void addDataSearchSubDirectory(const std::string& subdir); void addDataSearchSubDirectory(const std::string& subdir);
/*! @brief Try to find requested data file /*! @brief Try to find requested data file

View File

@ -1,5 +1,6 @@
#include "opencv2/ts.hpp" #include "opencv2/ts.hpp"
#include <opencv2/core/utils/logger.hpp> #include <opencv2/core/utils/logger.hpp>
#include "opencv2/core/utils/configuration.private.hpp"
#include "opencv2/core/utility.hpp" #include "opencv2/core/utility.hpp"
#if !defined(__EMSCRIPTEN__) #if !defined(__EMSCRIPTEN__)
#include "opencv2/core/private.hpp" #include "opencv2/core/private.hpp"

View File

@ -553,13 +553,9 @@ static int tsErrorCallback( int status, const char* func_name, const char* err_m
void TS::init( const string& modulename ) void TS::init( const string& modulename )
{ {
data_search_subdir.push_back(modulename); data_search_subdir.push_back(modulename);
#ifndef WINRT std::string datapath_dir = cv::utils::getConfigurationParameterString("OPENCV_TEST_DATA_PATH");
char* datapath_dir = getenv("OPENCV_TEST_DATA_PATH");
#else
char* datapath_dir = OPENCV_TEST_DATA_PATH;
#endif
if( datapath_dir ) if( !datapath_dir.empty() )
{ {
data_path = path_join(path_join(datapath_dir, modulename), ""); data_path = path_join(path_join(datapath_dir, modulename), "");
} }
@ -903,11 +899,7 @@ void parseCustomOptions(int argc, char **argv)
test_ipp_check = parser.get<bool>("test_ipp_check"); test_ipp_check = parser.get<bool>("test_ipp_check");
if (!test_ipp_check) if (!test_ipp_check)
#ifndef WINRT test_ipp_check = cv::utils::getConfigurationParameterBool("OPENCV_IPP_CHECK");
test_ipp_check = getenv("OPENCV_IPP_CHECK") != NULL;
#else
test_ipp_check = false;
#endif
param_seed = parser.get<unsigned int>("test_seed"); param_seed = parser.get<unsigned int>("test_seed");
@ -953,9 +945,14 @@ static bool isDirectory(const std::string& path)
void addDataSearchPath(const std::string& path) void addDataSearchPath(const std::string& path)
{ {
if (isDirectory(path)) if (!path.empty() && isDirectory(path))
TS::ptr()->data_search_path.push_back(path); TS::ptr()->data_search_path.push_back(path);
} }
void addDataSearchEnv(const std::string& env_name)
{
const std::string val = cv::utils::getConfigurationParameterString(env_name.c_str());
cvtest::addDataSearchPath(val);
}
void addDataSearchSubDirectory(const std::string& subdir) void addDataSearchSubDirectory(const std::string& subdir)
{ {
TS::ptr()->data_search_subdir.push_back(subdir); TS::ptr()->data_search_subdir.push_back(subdir);
@ -1001,14 +998,10 @@ static std::string findData(const std::string& relative_path, bool required, boo
const std::vector<std::string>& search_subdir = TS::ptr()->data_search_subdir; const std::vector<std::string>& search_subdir = TS::ptr()->data_search_subdir;
#ifndef WINRT std::string datapath_dir = cv::utils::getConfigurationParameterString("OPENCV_TEST_DATA_PATH");
char* datapath_dir = getenv("OPENCV_TEST_DATA_PATH");
#else
char* datapath_dir = OPENCV_TEST_DATA_PATH;
#endif
std::string datapath; std::string datapath;
if (datapath_dir) if (!datapath_dir.empty())
{ {
datapath = datapath_dir; datapath = datapath_dir;
//CV_Assert(isDirectory(datapath) && "OPENCV_TEST_DATA_PATH is specified but it doesn't exist"); //CV_Assert(isDirectory(datapath) && "OPENCV_TEST_DATA_PATH is specified but it doesn't exist");

View File

@ -192,22 +192,18 @@ void Regression::init(const std::string& testSuitName, const std::string& ext)
return; return;
} }
#ifndef WINRT const std::string data_path_dir = utils::getConfigurationParameterString("OPENCV_TEST_DATA_PATH");
const char *data_path_dir = getenv("OPENCV_TEST_DATA_PATH");
#else
const char *data_path_dir = OPENCV_TEST_DATA_PATH;
#endif
cvtest::addDataSearchSubDirectory(""); cvtest::addDataSearchSubDirectory("");
cvtest::addDataSearchSubDirectory(testSuitName); cvtest::addDataSearchSubDirectory(testSuitName);
const char *path_separator = "/"; const char *path_separator = "/";
if (data_path_dir) if (!data_path_dir.empty())
{ {
int len = (int)strlen(data_path_dir)-1; int len = (int)data_path_dir.size()-1;
if (len < 0) len = 0; if (len < 0) len = 0;
std::string path_base = (data_path_dir[0] == 0 ? std::string(".") : std::string(data_path_dir)) std::string path_base = (data_path_dir[0] == 0 ? std::string(".") : data_path_dir)
+ (data_path_dir[len] == '/' || data_path_dir[len] == '\\' ? "" : path_separator) + (data_path_dir[len] == '/' || data_path_dir[len] == '\\' ? "" : path_separator)
+ "perf" + "perf"
+ path_separator; + path_separator;
@ -1042,7 +1038,7 @@ void TestBase::Init(const std::vector<std::string> & availableImpls,
param_verify_sanity = args.get<bool>("perf_verify_sanity"); param_verify_sanity = args.get<bool>("perf_verify_sanity");
#ifdef HAVE_IPP #ifdef HAVE_IPP
test_ipp_check = !args.get<bool>("perf_ipp_check") ? getenv("OPENCV_IPP_CHECK") != NULL : true; test_ipp_check = !args.get<bool>("perf_ipp_check") ? utils::getConfigurationParameterBool("OPENCV_IPP_CHECK") : true;
#endif #endif
testThreads = args.get<int>("perf_threads"); testThreads = args.get<int>("perf_threads");
#ifdef CV_COLLECT_IMPL_DATA #ifdef CV_COLLECT_IMPL_DATA
@ -1125,12 +1121,11 @@ void TestBase::Init(const std::vector<std::string> & availableImpls,
#endif #endif
{ {
#ifndef WINRT std::string path = utils::getConfigurationParameterString("OPENCV_PERF_VALIDATION_DIR");
const char* path = getenv("OPENCV_PERF_VALIDATION_DIR"); #ifdef WINRT
#else path = OPENCV_PERF_VALIDATION_DIR;
const char* path = OPENCV_PERF_VALIDATION_DIR;
#endif #endif
if (path) if (!path.empty())
perf_validation_results_directory = path; perf_validation_results_directory = path;
} }
@ -1888,17 +1883,16 @@ std::string TestBase::getDataPath(const std::string& relativePath)
throw PerfEarlyExitException(); throw PerfEarlyExitException();
} }
#ifndef WINRT std::string data_path_dir = utils::getConfigurationParameterString("OPENCV_TEST_DATA_PATH");
const char *data_path_dir = getenv("OPENCV_TEST_DATA_PATH"); #ifdef WINRT
#else data_path_dir = OPENCV_TEST_DATA_PATH;
const char *data_path_dir = OPENCV_TEST_DATA_PATH;
#endif #endif
const char *path_separator = "/"; const char *path_separator = "/";
std::string path; std::string path;
if (data_path_dir) if (!data_path_dir.empty())
{ {
int len = (int)strlen(data_path_dir) - 1; int len = (int)data_path_dir.size() - 1;
if (len < 0) len = 0; if (len < 0) len = 0;
path = (data_path_dir[0] == 0 ? std::string(".") : std::string(data_path_dir)) path = (data_path_dir[0] == 0 ? std::string(".") : std::string(data_path_dir))
+ (data_path_dir[len] == '/' || data_path_dir[len] == '\\' ? "" : path_separator); + (data_path_dir[len] == '/' || data_path_dir[len] == '\\' ? "" : path_separator);

View File

@ -7,15 +7,7 @@
static static
void initTests() void initTests()
{ {
const char* extraTestDataPath = cvtest::addDataSearchEnv("OPENCV_DNN_TEST_DATA_PATH");
#ifdef WINRT
NULL;
#else
getenv("OPENCV_DNN_TEST_DATA_PATH");
#endif
if (extraTestDataPath)
cvtest::addDataSearchPath(extraTestDataPath);
cvtest::addDataSearchSubDirectory(""); // override "cv" prefix below to access without "../dnn" hacks cvtest::addDataSearchSubDirectory(""); // override "cv" prefix below to access without "../dnn" hacks
} }

View File

@ -7,6 +7,7 @@
#include "opencv2/ts.hpp" #include "opencv2/ts.hpp"
#include <opencv2/video.hpp> #include <opencv2/video.hpp>
#include "opencv2/ts/ts_perf.hpp" #include "opencv2/ts/ts_perf.hpp"
#include "opencv2/core/utils/configuration.private.hpp"
namespace cvtest namespace cvtest
{ {

View File

@ -10,15 +10,7 @@
static static
void initTests() void initTests()
{ {
const char* extraTestDataPath = cvtest::addDataSearchEnv("OPENCV_DNN_TEST_DATA_PATH");
#ifdef WINRT
NULL;
#else
getenv("OPENCV_DNN_TEST_DATA_PATH");
#endif
if (extraTestDataPath)
cvtest::addDataSearchPath(extraTestDataPath);
cvtest::addDataSearchSubDirectory(""); // override "cv" prefix below to access without "../dnn" hacks cvtest::addDataSearchSubDirectory(""); // override "cv" prefix below to access without "../dnn" hacks
} }

View File

@ -7,6 +7,7 @@
#include "opencv2/ts.hpp" #include "opencv2/ts.hpp"
#include "opencv2/video.hpp" #include "opencv2/video.hpp"
#include <opencv2/ts/ts_perf.hpp> #include <opencv2/ts/ts_perf.hpp>
#include "opencv2/core/utils/configuration.private.hpp"
namespace opencv_test { namespace opencv_test {
using namespace perf; using namespace perf;

View File

@ -332,16 +332,14 @@ std::vector<FileSystemPath_t> getPluginCandidates(const std::string& baseName)
std::vector<FileSystemPath_t> results; std::vector<FileSystemPath_t> results;
#ifdef _WIN32 #ifdef _WIN32
FileSystemPath_t moduleName = toFileSystemPath(libraryPrefix() + "opencv_videoio_" + baseName_l + librarySuffix()); FileSystemPath_t moduleName = toFileSystemPath(libraryPrefix() + "opencv_videoio_" + baseName_l + librarySuffix());
#ifndef WINRT
if (baseName_u == "FFMPEG") // backward compatibility if (baseName_u == "FFMPEG") // backward compatibility
{ {
const wchar_t* ffmpeg_env_path = _wgetenv(L"OPENCV_FFMPEG_DLL_DIR"); const std::string ffmpeg_env_path = cv::utils::getConfigurationParameterString("OPENCV_FFMPEG_DLL_DIR");
if (ffmpeg_env_path) if (!ffmpeg_env_path.empty())
{ {
results.push_back(FileSystemPath_t(ffmpeg_env_path) + L"\\" + moduleName); results.push_back(toFileSystemPath(ffmpeg_env_path + "\\" + toPrintablePath(moduleName)));
} }
} }
#endif
if (plugin_expr != default_expr) if (plugin_expr != default_expr)
{ {
moduleName = toFileSystemPath(plugin_expr); moduleName = toFileSystemPath(plugin_expr);

View File

@ -303,15 +303,7 @@ interface ISampleGrabber : public IUnknown
static void DebugPrintOut(const char *format, ...) static void DebugPrintOut(const char *format, ...)
{ {
static int gs_verbose = -1; static const bool gs_verbose = utils::getConfigurationParameterBool("OPENCV_DSHOW_DEBUG");
if (gs_verbose < 0)
{
// Fetch initial debug state from environment - defaults to disabled
const char* s = getenv("OPENCV_DSHOW_DEBUG");
gs_verbose = s != NULL && atoi(s) != 0;
}
if (gs_verbose) if (gs_verbose)
{ {
va_list args; va_list args;
@ -2982,18 +2974,18 @@ int videoInput::start(int deviceID, videoDevice *VD){
VD->readyToCapture = true; VD->readyToCapture = true;
// check for optional saving the direct show graph to a file // check for optional saving the direct show graph to a file
const char* graph_filename = getenv("OPENCV_DSHOW_SAVEGRAPH_FILENAME"); std::string graph_filename = utils::getConfigurationParameterString("OPENCV_DSHOW_SAVEGRAPH_FILENAME");
if (graph_filename) { if (!graph_filename.empty()) {
size_t filename_len = strlen(graph_filename); size_t filename_len = graph_filename.size();
std::vector<WCHAR> wfilename(filename_len + 1); std::vector<WCHAR> wfilename(filename_len + 1);
size_t len = mbstowcs(&wfilename[0], graph_filename, filename_len + 1); size_t len = mbstowcs(&wfilename[0], &graph_filename[0], filename_len + 1);
CV_Assert(len == filename_len); CV_Assert(len == filename_len);
HRESULT res = SaveGraphFile(VD->pGraph, &wfilename[0]); HRESULT res = SaveGraphFile(VD->pGraph, &wfilename[0]);
if (SUCCEEDED(res)) { if (SUCCEEDED(res)) {
DebugPrintOut("Saved DSHOW graph to %s\n", graph_filename); DebugPrintOut("Saved DSHOW graph to %s\n", graph_filename.c_str());
} else { } else {
DebugPrintOut("Failed to save DSHOW graph to %s\n", graph_filename); DebugPrintOut("Failed to save DSHOW graph to %s\n", graph_filename.c_str());
} }
} }

View File

@ -928,21 +928,19 @@ public:
} }
static void initLogger_() static void initLogger_()
{ {
#ifndef NO_GETENV const bool debug_option = utils::getConfigurationParameterBool("OPENCV_FFMPEG_DEBUG");
char* debug_option = getenv("OPENCV_FFMPEG_DEBUG"); std::string level_option = utils::getConfigurationParameterString("OPENCV_FFMPEG_LOGLEVEL");
char* level_option = getenv("OPENCV_FFMPEG_LOGLEVEL");
int level = AV_LOG_VERBOSE; int level = AV_LOG_VERBOSE;
if (level_option != NULL) if (!level_option.empty())
{ {
level = atoi(level_option); level = atoi(level_option.c_str());
} }
if ( (debug_option != NULL) || (level_option != NULL) ) if ( debug_option || (!level_option.empty()) )
{ {
av_log_set_level(level); av_log_set_level(level);
av_log_set_callback(ffmpeg_log_callback); av_log_set_callback(ffmpeg_log_callback);
} }
else else
#endif
{ {
av_log_set_level(AV_LOG_ERROR); av_log_set_level(AV_LOG_ERROR);
} }
@ -979,10 +977,10 @@ inline void fill_codec_context(AVCodecContext * enc, AVDictionary * dict)
{ {
int nCpus = cv::getNumberOfCPUs(); int nCpus = cv::getNumberOfCPUs();
int requestedThreads = std::min(nCpus, 16); // [OPENCV:FFMPEG:24] Application has requested XX threads. Using a thread count greater than 16 is not recommended. int requestedThreads = std::min(nCpus, 16); // [OPENCV:FFMPEG:24] Application has requested XX threads. Using a thread count greater than 16 is not recommended.
char* threads_option = getenv("OPENCV_FFMPEG_THREADS"); std::string threads_option = utils::getConfigurationParameterString("OPENCV_FFMPEG_THREADS");
if (threads_option != NULL) if (!threads_option.empty())
{ {
requestedThreads = atoi(threads_option); requestedThreads = atoi(threads_option.c_str());
} }
enc->thread_count = requestedThreads; enc->thread_count = requestedThreads;
} }
@ -1122,9 +1120,8 @@ bool CvCapture_FFMPEG::open(const char* _filename, const VideoCaptureParameters&
ic->interrupt_callback.opaque = &interrupt_metadata; ic->interrupt_callback.opaque = &interrupt_metadata;
#endif #endif
#ifndef NO_GETENV std::string options = utils::getConfigurationParameterString("OPENCV_FFMPEG_CAPTURE_OPTIONS");
char* options = getenv("OPENCV_FFMPEG_CAPTURE_OPTIONS"); if(!options.empty())
if(options == NULL)
{ {
#if LIBAVFORMAT_VERSION_MICRO >= 100 && LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(55, 48, 100) #if LIBAVFORMAT_VERSION_MICRO >= 100 && LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(55, 48, 100)
av_dict_set(&dict, "rtsp_flags", "prefer_tcp", 0); av_dict_set(&dict, "rtsp_flags", "prefer_tcp", 0);
@ -1136,14 +1133,11 @@ bool CvCapture_FFMPEG::open(const char* _filename, const VideoCaptureParameters&
{ {
CV_LOG_DEBUG(NULL, "VIDEOIO/FFMPEG: using capture options from environment: " << options); CV_LOG_DEBUG(NULL, "VIDEOIO/FFMPEG: using capture options from environment: " << options);
#if LIBAVUTIL_BUILD >= (LIBAVUTIL_VERSION_MICRO >= 100 ? CALC_FFMPEG_VERSION(52, 17, 100) : CALC_FFMPEG_VERSION(52, 7, 0)) #if LIBAVUTIL_BUILD >= (LIBAVUTIL_VERSION_MICRO >= 100 ? CALC_FFMPEG_VERSION(52, 17, 100) : CALC_FFMPEG_VERSION(52, 7, 0))
av_dict_parse_string(&dict, options, ";", "|", 0); av_dict_parse_string(&dict, options.c_str(), ";", "|", 0);
#else #else
av_dict_set(&dict, "rtsp_transport", "tcp", 0); av_dict_set(&dict, "rtsp_transport", "tcp", 0);
#endif #endif
} }
#else
av_dict_set(&dict, "rtsp_transport", "tcp", 0);
#endif
CV_FFMPEG_FMT_CONST AVInputFormat* input_format = NULL; CV_FFMPEG_FMT_CONST AVInputFormat* input_format = NULL;
AVDictionaryEntry* entry = av_dict_get(dict, "input_format", NULL, 0); AVDictionaryEntry* entry = av_dict_get(dict, "input_format", NULL, 0);
if (entry != 0) if (entry != 0)
@ -3095,12 +3089,12 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
} }
AVDictionary *dict = NULL; AVDictionary *dict = NULL;
#if !defined(NO_GETENV) && (LIBAVUTIL_VERSION_MAJOR >= 53) #if (LIBAVUTIL_VERSION_MAJOR >= 53)
char* options = getenv("OPENCV_FFMPEG_WRITER_OPTIONS"); std::string options = utils::getConfigurationParameterString("OPENCV_FFMPEG_WRITER_OPTIONS");
if (options) if (!options.empty())
{ {
CV_LOG_DEBUG(NULL, "VIDEOIO/FFMPEG: using writer options from environment: " << options); CV_LOG_DEBUG(NULL, "VIDEOIO/FFMPEG: using writer options from environment: " << options);
av_dict_parse_string(&dict, options, ";", "|", 0); av_dict_parse_string(&dict, options.c_str(), ";", "|", 0);
} }
#endif #endif

View File

@ -259,7 +259,7 @@ protected:
bool readPrioritySettings() bool readPrioritySettings()
{ {
bool hasChanges = false; bool hasChanges = false;
cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_VIDEOIO_PRIORITY_LIST", NULL); cv::String prioritized_backends = utils::getConfigurationParameterString("OPENCV_VIDEOIO_PRIORITY_LIST");
if (prioritized_backends.empty()) if (prioritized_backends.empty())
return hasChanges; return hasChanges;
CV_LOG_INFO(NULL, "VIDEOIO: Configured priority list (OPENCV_VIDEOIO_PRIORITY_LIST): " << prioritized_backends); CV_LOG_INFO(NULL, "VIDEOIO: Configured priority list (OPENCV_VIDEOIO_PRIORITY_LIST): " << prioritized_backends);

View File

@ -11,15 +11,13 @@
static static
void initTests() void initTests()
{ {
#ifndef WINRT // missing getenv
const std::vector<cv::VideoCaptureAPIs> backends = cv::videoio_registry::getStreamBackends(); const std::vector<cv::VideoCaptureAPIs> backends = cv::videoio_registry::getStreamBackends();
const char* requireFFmpeg = getenv("OPENCV_TEST_VIDEOIO_BACKEND_REQUIRE_FFMPEG"); bool requireFFmpeg = cv::utils::getConfigurationParameterBool("OPENCV_TEST_VIDEOIO_BACKEND_REQUIRE_FFMPEG");
if (requireFFmpeg && !isBackendAvailable(cv::CAP_FFMPEG, backends)) if (requireFFmpeg && !isBackendAvailable(cv::CAP_FFMPEG, backends))
{ {
CV_LOG_FATAL(NULL, "OpenCV-Test: required FFmpeg backend is not available (broken plugin?). STOP."); CV_LOG_FATAL(NULL, "OpenCV-Test: required FFmpeg backend is not available (broken plugin?). STOP.");
exit(1); exit(1);
} }
#endif
} }
CV_TEST_MAIN("highgui", initTests()) CV_TEST_MAIN("highgui", initTests())

View File

@ -13,6 +13,7 @@
#include "opencv2/videoio.hpp" #include "opencv2/videoio.hpp"
#include "opencv2/videoio/registry.hpp" #include "opencv2/videoio/registry.hpp"
#include "opencv2/core/private.hpp" #include "opencv2/core/private.hpp"
#include "opencv2/core/utils/configuration.private.hpp"
namespace cv { namespace cv {