opencv/modules/contrib/src/inputoutput.cpp

205 lines
7.0 KiB
C++
Raw Normal View History

#include "opencv2/contrib.hpp"
Merge remote-tracking branch 'origin/2.4' Conflicts: 3rdparty/ffmpeg/ffmpeg_version.cmake cmake/OpenCVFindLibsGrfmt.cmake cmake/templates/cvconfig.h.cmake modules/bioinspired/doc/retina/index.rst modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst modules/calib3d/src/precomp.hpp modules/contrib/src/inputoutput.cpp modules/contrib/src/precomp.hpp modules/core/include/opencv2/core/internal.hpp modules/core/include/opencv2/core/types_c.h modules/core/src/drawing.cpp modules/core/src/precomp.hpp modules/core/src/system.cpp modules/features2d/doc/common_interfaces_of_descriptor_matchers.rst modules/features2d/doc/common_interfaces_of_feature_detectors.rst modules/features2d/include/opencv2/features2d/features2d.hpp modules/features2d/src/precomp.hpp modules/flann/src/precomp.hpp modules/gpu/doc/camera_calibration_and_3d_reconstruction.rst modules/gpu/doc/image_filtering.rst modules/gpu/doc/image_processing.rst modules/gpu/doc/video.rst modules/gpu/perf/perf_imgproc.cpp modules/gpu/perf4au/main.cpp modules/gpu/src/imgproc.cpp modules/gpu/src/precomp.hpp modules/gpu/test/test_imgproc.cpp modules/highgui/CMakeLists.txt modules/highgui/test/test_precomp.hpp modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst modules/imgproc/src/precomp.hpp modules/java/generator/src/cpp/Mat.cpp modules/legacy/src/precomp.hpp modules/ml/doc/k_nearest_neighbors.rst modules/ml/src/precomp.hpp modules/nonfree/doc/feature_detection.rst modules/nonfree/src/precomp.hpp modules/objdetect/include/opencv2/objdetect/objdetect.hpp modules/objdetect/src/cascadedetect.cpp modules/objdetect/src/hog.cpp modules/objdetect/src/precomp.hpp modules/objdetect/test/test_latentsvmdetector.cpp modules/ocl/src/hog.cpp modules/ocl/src/opencl/objdetect_hog.cl modules/ocl/src/precomp.hpp modules/photo/src/precomp.hpp modules/stitching/src/precomp.hpp modules/superres/perf/perf_precomp.hpp modules/superres/src/optical_flow.cpp modules/superres/src/precomp.hpp modules/superres/test/test_precomp.hpp modules/ts/include/opencv2/ts.hpp modules/video/src/precomp.hpp modules/videostab/src/precomp.hpp modules/world/src/precomp.hpp
2013-08-06 13:56:49 +04:00
#include "cvconfig.h"
2012-10-17 11:12:04 +04:00
2013-05-29 01:14:01 -07:00
#if defined(WIN32) || defined(_WIN32)
2012-10-17 11:12:04 +04:00
#include <windows.h>
#include <tchar.h>
#else
#include <dirent.h>
#endif
namespace cv
{
std::vector<String> Directory::GetListFiles( const String& path, const String & exten, bool addPath )
2012-10-17 11:12:04 +04:00
{
std::vector<String> list;
2012-10-17 11:12:04 +04:00
list.clear();
String path_f = path + "/" + exten;
2012-10-17 11:12:04 +04:00
#ifdef WIN32
#ifdef HAVE_WINRT
WIN32_FIND_DATAW FindFileData;
#else
WIN32_FIND_DATAA FindFileData;
#endif
HANDLE hFind;
2012-10-17 11:12:04 +04:00
#ifdef HAVE_WINRT
wchar_t wpath[MAX_PATH];
size_t copied = mbstowcs(wpath, path_f.c_str(), MAX_PATH);
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
hFind = FindFirstFileExW(wpath, FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0);
#else
hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData);
#endif
2012-10-17 11:12:04 +04:00
if (hFind == INVALID_HANDLE_VALUE)
{
return list;
}
else
{
do
{
if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_NORMAL ||
FindFileData.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE ||
FindFileData.dwFileAttributes == FILE_ATTRIBUTE_HIDDEN ||
FindFileData.dwFileAttributes == FILE_ATTRIBUTE_SYSTEM ||
FindFileData.dwFileAttributes == FILE_ATTRIBUTE_READONLY)
{
char* fname;
#ifdef HAVE_WINRT
char fname_tmp[MAX_PATH] = {0};
size_t copied = wcstombs(fname_tmp, FindFileData.cFileName, MAX_PATH);
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
fname = fname_tmp;
#else
fname = FindFileData.cFileName;
#endif
2012-10-17 11:12:04 +04:00
if (addPath)
2013-08-06 17:06:13 +04:00
list.push_back(path + "/" + String(fname));
2012-10-17 11:12:04 +04:00
else
2013-08-06 17:06:13 +04:00
list.push_back(String(fname));
2012-10-17 11:12:04 +04:00
}
}
#ifdef HAVE_WINRT
while(FindNextFileW(hFind, &FindFileData));
#else
while(FindNextFileA(hFind, &FindFileData));
#endif
2012-10-17 11:12:04 +04:00
FindClose(hFind);
}
#else
(void)addPath;
DIR *dp;
struct dirent *dirp;
if((dp = opendir(path.c_str())) == NULL)
{
return list;
}
while ((dirp = readdir(dp)) != NULL)
{
if (dirp->d_type == DT_REG)
{
if (exten.compare("*") == 0)
list.push_back(static_cast<String>(dirp->d_name));
2012-10-17 11:12:04 +04:00
else
if (String(dirp->d_name).find(exten) != String::npos)
list.push_back(static_cast<String>(dirp->d_name));
2012-10-17 11:12:04 +04:00
}
}
closedir(dp);
#endif
return list;
}
std::vector<String> Directory::GetListFolders( const String& path, const String & exten, bool addPath )
2012-10-17 11:12:04 +04:00
{
std::vector<String> list;
String path_f = path + "/" + exten;
2012-10-17 11:12:04 +04:00
list.clear();
#ifdef WIN32
#ifdef HAVE_WINRT
WIN32_FIND_DATAW FindFileData;
#else
WIN32_FIND_DATAA FindFileData;
#endif
2012-10-17 11:12:04 +04:00
HANDLE hFind;
#ifdef HAVE_WINRT
wchar_t wpath [MAX_PATH];
size_t copied = mbstowcs(wpath, path_f.c_str(), path_f.size());
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
hFind = FindFirstFileExW(wpath, FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0);
#else
hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData);
#endif
2012-10-17 11:12:04 +04:00
if (hFind == INVALID_HANDLE_VALUE)
{
return list;
}
else
{
do
{
#ifdef HAVE_WINRT
2012-10-17 03:18:30 +04:00
if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY &&
wcscmp(FindFileData.cFileName, L".") != 0 &&
wcscmp(FindFileData.cFileName, L"..") != 0)
#else
2012-10-17 11:12:04 +04:00
if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY &&
strcmp(FindFileData.cFileName, ".") != 0 &&
strcmp(FindFileData.cFileName, "..") != 0)
#endif
2012-10-17 11:12:04 +04:00
{
char* fname;
#ifdef HAVE_WINRT
char fname_tmp[MAX_PATH];
2013-08-21 23:59:27 -07:00
size_t copied = wcstombs(fname_tmp, FindFileData.cFileName, MAX_PATH);
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
fname = fname_tmp;
#else
fname = FindFileData.cFileName;
#endif
2012-10-17 11:12:04 +04:00
if (addPath)
2013-08-06 17:06:13 +04:00
list.push_back(path + "/" + String(fname));
2012-10-17 11:12:04 +04:00
else
2013-08-06 17:06:13 +04:00
list.push_back(String(fname));
2012-10-17 11:12:04 +04:00
}
}
#ifdef HAVE_WINRT
while(FindNextFileW(hFind, &FindFileData));
#else
while(FindNextFileA(hFind, &FindFileData));
#endif
2012-10-17 11:12:04 +04:00
FindClose(hFind);
}
#else
(void)addPath;
DIR *dp;
struct dirent *dirp;
if((dp = opendir(path_f.c_str())) == NULL)
{
return list;
}
while ((dirp = readdir(dp)) != NULL)
{
if (dirp->d_type == DT_DIR &&
strcmp(dirp->d_name, ".") != 0 &&
strcmp(dirp->d_name, "..") != 0 )
{
if (exten.compare("*") == 0)
list.push_back(static_cast<String>(dirp->d_name));
2012-10-17 11:12:04 +04:00
else
if (String(dirp->d_name).find(exten) != String::npos)
list.push_back(static_cast<String>(dirp->d_name));
2012-10-17 11:12:04 +04:00
}
}
closedir(dp);
#endif
return list;
}
std::vector<String> Directory::GetListFilesR ( const String& path, const String & exten, bool addPath )
2012-10-17 11:12:04 +04:00
{
std::vector<String> list = Directory::GetListFiles(path, exten, addPath);
2012-10-17 11:12:04 +04:00
std::vector<String> dirs = Directory::GetListFolders(path, exten, addPath);
2012-10-17 11:12:04 +04:00
std::vector<String>::const_iterator it;
2012-10-17 11:12:04 +04:00
for (it = dirs.begin(); it != dirs.end(); ++it)
{
std::vector<String> cl = Directory::GetListFiles(*it, exten, addPath);
2012-10-17 11:12:04 +04:00
list.insert(list.end(), cl.begin(), cl.end());
}
return list;
}
}