前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >opencv(一):Directory(遍历目录下的文件(夹))

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

作者头像
ke1th
发布2018-01-02 11:37:16
1.5K0
发布2018-01-02 11:37:16
举报

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 就是获取指定文件夹下的 文件夹了。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • opencv 工具类 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)
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档