Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

opencv

I am new to OpenCV. I want to read XML files in a directory. I am using FindFirstFile, but I am not getting how can I get file names to give as input to cvLoad further. Here is the code I am using:

HANDLE hFind;
WIN32_FIND_DATA FindFileData;
wchar_t* file = L"D:\\zainb_s\\M.phil\\thesis\\dataset\\dataset_3\\RGB_3\\RGB\\s01_e01-   Copy\\1_walking\\depth\\*.xml";
hFind = FindFirstFile(file, &FindFileData);
cout << FindFileData.cFileName[0];
FindClose(hFind);

I want to have filenames in an array to read files further to process.

like image 536
Zainb Avatar asked Oct 23 '14 19:10

Zainb


1 Answers

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!!)

like image 65
berak Avatar answered Nov 15 '22 07:11

berak