博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
遍历文件夹下图片的方法
阅读量:4107 次
发布时间:2019-05-25

本文共 931 字,大约阅读时间需要 3 分钟。

在做图像处理相关的任务时,经常遇到要遍历文件夹下所有图像的问题,实现图像的批处理,所以特地查找了遍历文件夹的方法,现总结如下:

实现思路是根据给定的文件夹路径,将该文件夹下的图像都存储近一个vector中,功能实现整合为一个函数,如下:

void getFiles(string path, vector
& files){ long hFile = 0; struct _finddata_t fileinfo; string p; if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) { do { if ((fileinfo.attrib & _A_SUBDIR)) { if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) getFiles(p.assign(path).append("\\").append(fileinfo.name), files); } else { files.push_back(p.assign(path).append("\\").append(fileinfo.name)); } } while (_findnext(hFile, &fileinfo) == 0); _findclose(hFile); }}

调用的大致步骤为:

char * filePath = "D:\\data\\train_image";vector
files;getFiles(filePath, files);int number = files.size();for (int i = 0; i < number; i++){ //利用循环遍历文件夹里的每一张图像 Mat SrcImage = imread(files[i].c_str()); ……//你的功能代码 }

根据自己文件夹的路径,对应修改filePath。

转载地址:http://xxssi.baihongyu.com/

你可能感兴趣的文章
C# 发HTTP请求
查看>>
初试visual studio2012的新型数据库LocalDB
查看>>
启动 LocalDB 和连接到 LocalDB
查看>>
Palindrome Number --回文整数
查看>>
Reverse Integer--反转整数
查看>>
Container With Most Water --装最多水的容器(重)
查看>>
Longest Common Prefix -最长公共前缀
查看>>
Letter Combinations of a Phone Number
查看>>
Single Number II --出现一次的数(重)
查看>>
Valid Parentheses --括号匹配
查看>>
Generate Parentheses--生成匹配括号(重)
查看>>
Remove Element--原地移除重复元素
查看>>
Remove Duplicates from Sorted Array--从有序数组中移除重复元素
查看>>
Count and Say
查看>>
Gas Station
查看>>
Palindrome Partitioning --回文切割 深搜(重重)
查看>>
Valid Palindrome 简单的回文判断
查看>>
Triangle --找三角形数组中最小的路径(重重重)
查看>>
Pascal's Triangle -- 生成杨辉三角
查看>>
Pascal's Triangle II 生成杨辉三角中的某行
查看>>