問題描述
我是 OpenCV 的新手.我想讀取目錄中的 XML 文件.我正在使用 FindFirstFile,但我不知道如何獲取文件名以進(jìn)一步作為 cvLoad 的輸入.這是我正在使用的代碼:
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);
我想在一個數(shù)組中包含文件名以進(jìn)一步讀取文件以進(jìn)行處理.
I want to have filenames in an array to read files further to process.
推薦答案
如果您使用的是最新版本的 OpenCV,最好避免使用特定于操作系統(tǒng)的方法:
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.
(哦,再一次,避免不推薦使用的 C-API 函數(shù),比如 cvLoad地獄,拜托!!)
(Ohh, and again, avoid deprecated C-API functions like cvLoad like hell, please!!)
這篇關(guān)于如何從OpenCV中的目錄中依次讀取文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!