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++.
Asked
Active
Viewed 1.9k times
8
-
Here is the [possible duplicate topic](http://stackoverflow.com/questions/8401777/simple-glob-in-c-on-unix-system) – MichalSzczep Feb 16 '17 at 14:28
1 Answers
27
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]));

berak
- 39,159
- 9
- 91
- 89
-
thank for answer. If I will show an image fn[ i ] . I write imshow("picture",fn[ i ]); or imshow("pic",image); between for(...) and images.push_back .it not work fine for me. – Nungning Jul 15 '15 at 19:04
-
I understand to show an image by change type of count from size_t to int thank you berak :D – Nungning Jul 15 '15 at 20:29
-
@Nungning Works Perfectly fine for any kind of vector variable, Thank you – Ahmet Dec 19 '15 at 19:04
-