opencv(一):Directory(遍历目录下的文件(夹))

本文介绍了OpenCV中的Directory工具类,该类提供了获取指定路径下文件及子文件夹的功能。包括GetListFiles、GetListFilesR及GetListFolders三个静态函数,分别用于获取指定目录下的文件、递归获取所有文件以及获取文件夹。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

opencv 工具类 Directory

opencv2 提供了一个 Directory 工具类来帮助读取文件夹中的文件名,这还是挺方便的,因为 目前常用的 c++ 版本并没有提供简单的文件名读取接口。这个工具类在contrib.hpp下。

注意:opencv3. 把contrib库从默认库中拿出来,如果想用这个工具类的话,需要自己重新把contrib编译一下。

Directory类包含三个静态函数,分别是:

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

static std::vector< std::string > GetListFiles (const std::string &path, const std::string &exten=”*”, bool addPath=true)

这个函数只获取指定目录下的文件, 不理会目录

  • path:string, 用于指定根目录
  • exten: string,这个是个正则表达式,匹配的返回,否则不返回。
  • addPath: bool,如果为true,返回的文件名会带path,如果为false,返回的仅是文件名。

static std::vector< std::string > GetListFilesR (const std::string &path, const std::string &exten=”*”, bool addPath=true)

这个API比上面多了个R,这个R代表的recursive的意思,就是碰到文件夹还是往里钻。

static std::vector< std::string > GetListFolders (const std::string &path, const std::string &exten=”*”, bool addPath=true)

这个API 就是获取指定文件夹下的 文件夹了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值