如何从OpenCV中的目录顺序读取文件? [英] How to read files in sequence from a directory in OpenCV?

查看:841
本文介绍了如何从OpenCV中的目录顺序读取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 OpenCV 的新用户。我想读一个目录中的XML文件。我使用FindFirstFile,但我不知道如何获得文件名作为输入给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);

我想在数组中有文件名,以便进一步读取文件。

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

推荐答案

如果您使用的是最新版本的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.

(哦,再次,避免弃用C-API函数,如cvLoad like hell ,请!!)

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

这篇关于如何从OpenCV中的目录顺序读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆