C++ 读取目录下的所有图片
2017-11-22 09:43
204 查看
C++ 读取目录下的所有图片
#include <string> #include "utils.h" #include <stdio.h> #include <direct.h> #include <iostream> #include <io.h> using namespace std; using namespace cv; string trainPath = "F://vido and images fro test//UIUC texture database"; //获取目录下的所有文件夹 void getClassName(string path, vector<string>& classNames) { intptr_t hFile = 0; struct _finddata_t fileinfo; string p; hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo); if (hFile != -1) { while (_findnext(hFile, &fileinfo) == 0) { if (fileinfo.attrib & _A_SUBDIR) { if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) { //classNames.push_back(p.assign(path).append("/").append(fileinfo.name));//保存文件夹名字 classNames.push_back(fileinfo.name);//保存类名 } } } } } //遍历每个文件夹下的图片,并保存为fileList void getImages(string path, vector<string>& imagesList) { intptr_t hFile = 0; struct _finddata_t fileinfo; string p; hFile = _findfirst(p.assign(path).append("\\*.jpg").c_str(), &fileinfo); if (hFile != -1) { do { imagesList.push_back(fileinfo.name);//保存类名 } while (_findnext(hFile, &fileinfo) == 0); } } //获取所有图片 void getAllImages(string path, vector<vector<string>>& fileLists) { vector<string> paths; vector<string > fileList; string classPath; getClassName(path, paths); for (vector<string>::const_iterator p = paths.begin(); p != paths.end(); p++) { fileList.clear(); classPath = path; classPath.append("/").append(*p); getImages(classPath, fileList); fileLists.push_back(fileList); } } void test() { vector<vector<string>> fileLists; getAllImages(trainPath, fileLists); for (int i = 0; i < fileLists.size(); i++) { for (vector<string>::const_iterator p = fileLists[i].begin(); p != fileLists[i].end(); p++) cout << *p << endl; } }
相关文章推荐
- 读取安卓assets目录下的所有图片并显示
- C++读取某一目录下的所有文件名
- C++读取某一目录下的所有文件名
- 【c++】读取目录下所有文件
- 如何用几行代码读取目录下所有的图片
- jdk7 NIO的读取目录下所有图片(文件)
- c++读取文件目录下所有文件并输出
- 毕业设计——人脸检测——004 学习别人代码——《matlab读取一个目录下的所有图片》
- tips:matlab读取一个目录下的所有图片
- Android读取assets目录下的所有图片并显示的方法
- 如何用几行代码读取目录下所有的图片
- C++读取目录下所有文件名
- OpenCV/C/C++读取文件夹内所有图或者多张图片
- windows下c++读取一个目录下的所有文件
- c++ 读取所有图片
- 如何用几行代码读取目录下所有的图片
- c++读取目录下所有文件名
- 基于C/C++的读取文件夹下所有文件(图片、文档等)的代码
- C++ 递归读取目录下所有文件
- C++读取所有图片