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
?cout<<"file names: "< ?string path2 = "E:/data/image"; ?vector ?cout<<"folder names: "< ?string path3 = "E:/data/image"; ?vector ?cout<<"all file names: "< --------------------------------------分割线 -------------------------------------- --------------------------------------分割线 --------------------------------------
? cout<
?string exten2 = "*";//"Image*";//"*"
?bool addPath2 = true;//false
? cout<
?string exten3 = "*";
?bool addPath3 = true;//false
? cout<