7

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++.

Glorfindel
  • 20,880
  • 13
  • 75
  • 99
Nungning
  • 83
  • 1
  • 2
  • 6

1 Answers1

25

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
  • 37,825
  • 9
  • 89
  • 86
  • 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 – Ahx Dec 19 '15 at 19:04
  • I am getting assertion faild in debug mode and idies why ? – Stav Bodik Nov 03 '17 at 06:55