提交 ed41782e 编写于 作者: S sjtubinlong

Update C++ infer: search images on windows os

上级 2f36f8cb
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
#include <opencv2/highgui/highgui.hpp> #include <opencv2/highgui/highgui.hpp>
#ifdef _WIN32 #ifdef _WIN32
#include <filesystem> #define GLOG_NO_ABBREVIATED_SEVERITIES
#include <windows.h>
#else #else
#include <dirent.h> #include <dirent.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -67,15 +68,21 @@ namespace utils { ...@@ -67,15 +68,21 @@ namespace utils {
// scan a directory and get all files with input extensions // scan a directory and get all files with input extensions
inline std::vector<std::string> get_directory_images( inline std::vector<std::string> get_directory_images(
const std::string& path, const std::string& exts) { const std::string& path, const std::string& exts) {
std::string pattern(path);
pattern.append("\\*");
std::vector<std::string> imgs; std::vector<std::string> imgs;
for (const auto& item : WIN32_FIND_DATA data;
std::experimental::filesystem::directory_iterator(path)) { HANDLE hFind;
auto suffix = item.path().extension().string(); if ((hFind = FindFirstFile(pattern.c_str(), &data)) != INVALID_HANDLE_VALUE) {
if (exts.find(suffix) != std::string::npos && suffix.size() > 0) { do {
auto fullname = path_join(path, auto fname = std::string(data.cFileName);
item.path().filename().string()); auto pos = fname.rfind(".");
imgs.push_back(item.path().string()); auto ext = fname.substr(pos + 1);
} if (ext.size() > 1 && exts.find(ext) != std::string::npos) {
imgs.push_back(path + "\\" + data.cFileName);
}
} while (FindNextFile(hFind, &data) != 0);
FindClose(hFind);
} }
return imgs; return imgs;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册