opencv 获取一个目录下子目录_opencv实现遍历文件夹下所有文件

前言

最近需要将视频数据集中的每个视频进行分割,分割成等长的视频片段,前提是需要首先遍历数据集文件夹中的所有视频。

实现

1.了解opencv中的Directory类;

2.实现测试代码;

系统环境

OS:win7_64;

opencv版本:2.4.10;

VS版本:VS2013

实现过程

1.了解opencv中的Directory类;

1)opencv中有实现遍历文件夹下所有文件的类Directory,包含3个成员函数:

(1)GetListFiles:遍历指定文件夹下的所有文件,不包括指定文件夹内的文件夹;

(2)GetListFolders:遍历指定文件夹下的所有文件夹,不包括指定文件夹下的文件;

(3)GetListFilesR:遍历指定文件夹下的所有文件,包括指定文件夹内的文件夹。

classCV_EXPORTS Directory

{public:static std::vector<:string> GetListFiles ( const std::string& path, const std::string & exten = "*", bool addPath = true);static std::vector<:string> GetListFilesR ( const std::string& path, const std::string & exten = "*", bool addPath = true);static std::vector<:string> GetListFolders( const std::string& path, const std::string & exten = "*", bool addPath = true);

};

注意,其中addPath变量表示输出变量是否add到path变量;

2)若要使用Directory类,则需包含contrib.hpp头文件,此类的实现在contrib模块。

模块的具体路径:

.\opencv\build\include\opencv2\contrib

#include “opencv2/contrib/contrib.hpp”

2.实现测试代码;

cv::Directory dir;string path1 = "E:/data/image";string exten1 = "*.bmp";//"*"

bool addPath1 = false;//true;

vector filenames =dir.GetListFiles(path1, exten1, addPath1);

cout<

cout<

bool addPath2 = true;//false

vector foldernames =dir.GetListFolders(path2, exten2, addPath2);

cout<

cout<

vector allfilenames =dir.GetListFilesR(path3, exten3, addPath3);

cout<

cout<

问题:

实现的过程中出现warning提示,

warning C4101:“dir”:未引用的局部变量;

暂时还没有找到这个warning的解决方法;不过不影响实现;

参考

2.实例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值