C++图像批处理:读取文件夹中全部图像的方法

来源:互联网 发布:苏州网络推广外包 编辑:程序博客网 时间:2024/05/22 14:01
string file_path = "H:\\image data\\";
string search_path = file_path + "*.jpg";
vector<string> file_list;
if (!get_filelist_from_dir(search_path, file_list))
cout << "open file error!" << endl;
for (int i = 0; i < file_list.size(); i++)
{
string image_path = file_path + file_list[i];
Mat image = imread(image_path);
/*处理*/
}
get_filelist_from_dir()函数的定义如下:
#include <io.h>
bool get_filelist_from_dir(string path, vector<string>& files)
{
long   hFile   =   0;
struct _finddata_t fileinfo;
files.clear();
if((hFile = _findfirst(path.c_str(), &fileinfo)) !=  -1)
{
do
{
if(!(fileinfo.attrib &  _A_SUBDIR))
files.push_back(fileinfo.name);
}while(_findnext(hFile, &fileinfo)  == 0);
_findclose(hFile);
return true;
}
else
return false;
}
阅读全文
0 0
原创粉丝点击