话不多说,直接上代码:
#include <iostream>
#include <dirent.h>
#include <opencv2/highgui.hpp>
using namespace std;
std::vector<std::string>readFolder(const std::string &image_path)
{
std::vector<std::string> image_names;
auto dir = opendir(image_path.c_str());
if ((dir) != nullptr)
{
struct dirent *entry;
entry = readdir(dir);
while (entry)
{
auto temp = image_path + "/" + entry->d_name;
if (strcmp(entry->d_name, "") == 0 || strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
{
entry = readdir(dir);
continue;
}
image_names.push_back(temp);
entry = readdir(dir);
}
}
return image_names;
}
int main()
{
# 得到所有文件路径
auto ss = readFolder("./res");
for (const auto& i:ss)
{
cv::Mat src_img = cv::imread(i);
}
return 0;
}