OpenCV implement Traverse folder all files

Source: Internet
Author: User

OPENCV has a class directory that implements all the files that traverse the folder, which includes 3 member functions: (1), Getlistfiles: Iterates through all the files under the specified folder, excludes folders within the specified folder, (2), Getlistfolders: Traverse all folders under the specified folder, excluding files under the specified folder, (3), GETLISTFILESR: Iterates through all files under the specified folder, including folders within the specified folder.

To use the directory class, you need to include the CONTRIB.HPP header file, the implementation of this class in the contrib module.

The following is the test code:

CV::D irectory 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;//falsevector<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;// falsevector<string> allfilenames = dir. GETLISTFILESR (Path3, Exten3, AddPath3);cout<< "All file names:" <<endl;for (int i = 0; I < allfilenames.size (); i++) Cout<<allfilenames[i]<<endl; 


OpenCV implement Traverse folder all files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.