OpenCV杂记05---遍历文件夹内全部文件
2016-04-20 21:59
239 查看
原文地址
http://blog.csdn.net/fengbingchun/article/details/42435901#commentsOpenCV中有实现遍历文件夹下所有文件的类Directory,它里面包括3个成员函数:
(1)、GetListFiles:遍历指定文件夹下的所有文件,不包括指定文件夹内的文件夹;
(2)、GetListFolders:遍历指定文件夹下的所有文件夹,不包括指定文件夹下的文件;
(3)、GetListFilesR:遍历指定文件夹下的所有文件,包括指定文件夹内的文件夹。
仅对GetListFiles做了测试。附上代码。
#include<iostream> #include <opencv2/opencv.hpp> //#include <opencv2/core/core.hpp> //#include <opencv2/highgui/highgui.hpp> using namespace cv; using namespace std; int main() { Directory dir; string path; string path1 = "D:/TestImage/"; // folder path string exten1 = "*.jpg"; // or scan all files with "*" bool addPath1 = false; //true; 此处存疑。 vector<string> filenames = dir.GetListFiles(path1, exten1, addPath1); cout<<"The number of files in "<< path1 << " : \n" ; cout<< filenames.size()<<"\n"; cout<<"files' name: \n"; //string path="D:/TestImage/IMG_2907.JPG"; //Mat img = imread(path); //imshow(path1,img); for (int i = 0; i < filenames.size(); i++) { path = path1 + filenames[i]; // add two strings cout<<path<<endl; //cout<<filenames[i]<<endl; Mat img = imread(path); imshow(path,img); } waitKey(0); return 0; }
相关文章推荐
- tomcat 性能优化
- Linux 内核开发 - 内核定时器
- 使用Get方式提交数据到Tomcat服务器
- 如何用OpenCV跟踪鼠标操作
- OpenCV杂记04---include头文件重复及各模块介绍
- 虚拟机linux配置NFS
- Centos安装protobuf
- 开源tinyXMl和OpenCV读写XML文件对比
- Linux学习期中总结
- CentOS 6上搭建LAMP
- Linux内核分析期中总结
- linux 恢复误删除文件
- centos6.5下安装django
- 网站开发常用技巧收集(防复制,防另存等等)
- Linux:常用命令
- 每天一个linux命令(11):nl命令
- Linux命令之for - Bash中的For循环
- Photoshop CC 2015 for MAC【中文安装包及超简单5秒破解】
- OpenCV杂记03---Scalar,row,col,cout
- windows server 2003更新后 启动网站提示另一个程序正在使用此文件,进程无法访问 关闭phpstudy全部停止再启动OK