前言

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

实现

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:遍历指定文件夹下的所有文件,包括指定文件夹内的文件夹。

class CV_EXPORTS Directory
{
public:
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 );
};

注意,其中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<string> filenames = dir.GetListFiles(path1, exten1, addPath1); cout<<"file names: "<<endl;
for (int i = ; i < filenames.size(); i++)
cout<<filenames[i]<<endl; string path2 = "E:/data/image";
string exten2 = "*";//"Image*";//"*"
bool addPath2 = true;//false vector<string> foldernames = dir.GetListFolders(path2, exten2, addPath2); cout<<"folder names: "<<endl;
for (int i = ; i < foldernames.size(); i++)
cout<<foldernames[i]<<endl; string path3 = "E:/data/image";
string exten3 = "*";
bool addPath3 = true;//false vector<string> allfilenames = dir.GetListFilesR(path3, exten3, addPath3); cout<<"all file names: "<<endl;
for (int i = ; i < allfilenames.size(); i++)
cout<<allfilenames[i]<<endl;

问题:
实现的过程中出现warning提示,

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

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

参考

1.大牛博客

2.实例

最新文章

  1. 错误:媒体集有 2 个媒体簇,但只提供了 1 个 sql2005 备份错误。
  2. C++多线程编程(入门实例)
  3. ORACLE 10进制与16进制的互相转换
  4. SOA面向服务架构简述
  5. KMS错误代码收集
  6. Git Cmd
  7. c语言指针说解
  8. 安卓模拟器还是&quot;genymotion&quot;最靠谱.
  9. 常用Firefox扩展
  10. Apple Watch 1.0 开发介绍 1.1 简介 开发苹果手表
  11. Android之自定义Adapter的ListView
  12. [ABP开源项目]--vue+vuex+vue-router+EF的权限管理系统
  13. python模块之_正则 re_configparser_logging_hashlib
  14. 文笔很差系列1 - 也谈谈AlphaGo
  15. python导包路径的修改
  16. python class中__init__函数、self
  17. EZ 2018 05 20 NOIP2018 模拟赛(十五)
  18. 【DS】排序算法之快速排序(Quick Sort)
  19. On premise TFS Git OAuth clone failed on agent
  20. codeforces 350 div2 C. Cinema map标记

热门文章

  1. CASSANDRA How to import and export data
  2. 使用R内置函数操作数据框
  3. 技术分享:SSH实战项目
  4. 《剑指offer》第二十题(表示数值的字符串)
  5. 多年未写过java了
  6. crond 的注意点
  7. 关于c#除法运算的问题
  8. 谈谈http与https
  9. hdu1358 kmp的next数组
  10. iframe刷新父页面