How to read files in sequence from a directory in OpenCV?

If you’re using a recent version of OpenCV, you’re better off avoiding OS-specific methods:

vector<string> fn; // std::string in opencv2.4, but cv::String in 3.0
string path = "e:/code/vlc/faces2/*.png";
cv::glob(path,fn,false);
// Now you got a list of filenames in fn.

(Ohh, and again, avoid deprecated C-API functions like cvLoad like hell, please!!)

Leave a Comment