首页 / 操作系统 / Linux / OpenCV实现遍历文件夹下所有文件
OpenCV中有实现遍历文件夹下所有文件的类Directory,它里面包括3个成员函数:(1)、GetListFiles:遍历指定文件夹下的所有文件,不包括指定文件夹内的文件夹;(2)、GetListFolders:遍历指定文件夹下的所有文件夹,不包括指定文件夹下的文件;(3)、GetListFilesR:遍历指定文件夹下的所有文件,包括指定文件夹内的文件夹。若要使用Directory类,则需包含contrib.hpp头文件,此类的实现在contrib模块。下面为测试代码: cv::Directory dir; string path1 = "E:/data/image";
string exten1 = "*.bmp";//"*"
bool addPath1 = false;//true; vector<string> filenames = dir.GetListFiles(path1, exten1, addPath1); cout<<"file names: "<<endl;
for (int i = 0; i < filenames.size(); i++)
cout<<filenames[i]<<endl; string path2 = "E:/data/image";
string exten2 = "*";//"Image*";//"*"
bool addPath2 = true;//false vector<string> foldernames = dir.GetListFolders(path2, exten2, addPath2); cout<<"folder names: "<<endl;
for (int i = 0; i < foldernames.size(); i++)
cout<<foldernames[i]<<endl; string path3 = "E:/data/image";
string exten3 = "*";
bool addPath3 = true;//false vector<string> allfilenames = dir.GetListFilesR(path3, exten3, addPath3); cout<<"all file names: "<<endl;
for (int i = 0; i < allfilenames.size(); i++)
cout<<allfilenames[i]<<endl;--------------------------------------分割线 --------------------------------------Ubuntu Linux下安装OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htmUbuntu 12.04 安装 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htmCentOS下OpenCV无法读取视频文件 http://www.linuxidc.com/Linux/2011-07/39295.htmUbuntu 12.04下安装OpenCV 2.4.5总结 http://www.linuxidc.com/Linux/2013-06/86704.htmUbuntu 10.04中安装OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm基于QT和OpenCV的人脸识别系统 http://www.linuxidc.com/Linux/2011-11/47806.htm[翻译]Ubuntu 14.04, 13.10 下安装 OpenCV 2.4.9 http://www.linuxidc.com/Linux/2014-12/110045.htm--------------------------------------分割线 --------------------------------------OpenCV的详细介绍:请点这里
OpenCV的下载地址:请点这里本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-01/111349.htm