1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

[build][option] Build option to disable filesystem support.

This commit is contained in:
Francesco Petrogalli
2021-04-29 16:32:51 +00:00
parent df05bc65c5
commit 7a31a6edee
7 changed files with 88 additions and 3 deletions
+40 -2
View File
@@ -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
}
+7
View File
@@ -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()
@@ -947,6 +949,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 +1036,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;
+19
View File
@@ -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
+8
View File
@@ -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
}