I have a problem. I'm writing C++ with the openCV library. I want to get the number of all images in a folder and I want to load all images in the folder for process in C++.
Have a look at the DirectoryInfo. GetFiles overload that takes a SearchOption argument and pass SearchOption. AllDirectories to get the files including all sub-directories.
You can use below code to get all images from specific folder. 1) First you need to define File object to get the storage and appened the name of the folder you want to read. File folder = new File(Environment. getExternalStorageDirectory().
you can use glob to get a list of filenames:
vector<cv::String> fn;
glob("/home/images/*.png", fn, false);
vector<Mat> images;
size_t count = fn.size(); //number of png files in images folder
for (size_t i=0; i<count; i++)
images.push_back(imread(fn[i]));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With