前言

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

实现

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.实例

opencv实现遍历文件夹下所有文件的更多相关文章

  1. C#遍历文件夹下所有文件

    FolderForm.cs的代码如下: using System; using System.Collections.Generic; using System.Diagnostics; using ...

  2. python (9)统计文件夹下的所有文件夹数目、统计文件夹下所有文件数目、遍历文件夹下的文件

    命令:os 用到的:os.walk   os.listdir 写的爬虫爬的数据,但是又不知道进行到哪了,于是就写了个脚本来统计文件的个数 #统计 /home/dir/ 下的文件夹个数 import o ...

  3. PHP遍历文件夹下的文件和获取到input name的值

    <?php$dir = dirname(__FILE__); //要遍历的目录名字 ->当前文件所在的文件夹//$dir='D:\PHP\wamp\www\admin\hosts\admi ...

  4. java中File类应用:遍历文件夹下所有文件

    练习: 要求指定文件夹下的所有文件,包括子文件夹下的文件 代码: package 遍历文件夹所有文件; import java.io.File; public class Test { public ...

  5. c bash 代码遍历文件夹下所有文件

    用C代码.bash实现代码遍历文件夹下所有文件 递归方式实现如下: void listdir(char *path) { DIR *ptr_dir; struct dirent *dir_entry; ...

  6. PHP使用glob方法遍历文件夹下所有文件

    PHP使用glob方法遍历文件夹下所有文件 遍历文件夹下所有文件,一般可以使用opendir 与 readdir 方法来遍历.<pre><?php$path = dirname(__ ...

  7. 利用shell脚本或者php移动某个文件夹下的文件到各自的日期组成的目录下

    背景是这样的:网站一开始访问量比较小,大家就把所有的图片文件上传到一个目录下(比如是/data/images/).后来访问量大了,图片也多了,这样就影响读取效率.所以有个这样的需求,把这些个图片文件移 ...

  8. FILE文件删除操作(删除指定文件夹下所有文件和文件夹包括子文件夹下所有文件和文件夹),就是删除所有

    2018-11-05  19:42:08开始写 选择 删除 1.FileUtils.java类 import java.io.File;//导入包 import java.util.List;//导入 ...

  9. python 替换 文件夹下的 文件名称 及 文件内容

    示例效果: 1.替换某文件夹下的 文件夹及子文件夹 的名称 由OldStrDir 变为 NewStrDir: 2.替换某文件夹下的 文件夹及子文件夹 下 所有的文件的名称 由OldStrFile 变为 ...

随机推荐

  1. lambda表达式/对象引用计数

    ★lambda表达式的用法例:I=[(lambda x: x*2),(lambda y: y*3)]调用:for x in I: print x(2)输出:4,6 ★获取对象的引用次数sys.getr ...

  2. 手动添加 launcher 到 Ubuntu Unity

    本来,启动程序之后,在左边的launcher bar点右键,[Lock to Launcher]就可以的. 但是,有时候因为某种原因,需要手工添加. 这时候,就要参考下面的文章了 http://ask ...

  3. 关于 [TNS-12516 TNS:listener could not find instance with matching protocol stack ]

    Title: Intermittent TNS-12516 or TNS-12519 Errors Connecting Via Net Symptom(s) ~~~~~~~~~~ Client co ...

  4. 开发shellcode的艺术

    专业术语 ShellCode:实际是一段代码(也可以是填充数据) exploit:攻击通过ShellCode等方法攻击漏洞 栈帧移位与jmp esp 一般情况下,ESP寄存器中的地址总是指向系统栈且不 ...

  5. 最小生成树 - 克鲁斯卡尔 - 并查集 - 边稀疏 - O(E * logE)

    #define _CRT_SECURE_NO_WARNINGS #include<cstdio> #include<cstring> #include<algorithm ...

  6. spark collect获取所有元素

    from pyspark import SparkConf, SparkContext conf = SparkConf().setMaster("local").setAppNa ...

  7. 使用iview-project 打包build报错,ERROR in xxxxx.cheunk.js from UglifyJs

    一.iview-project  为iview官方推荐工程,一个基于iview的vue脚手架 github网址:https://github.com/iview/iview-project 废话不多说 ...

  8. cnblogs插件jiathis

    博客园cnblogs增加分享插件 <!--jiathis button Begin--> <div id="ckepop"> <span class= ...

  9. duilib 实现 XML重用(item完全重合的CList)

    最近做一个项目,界面库用的是duilib. 软件首页的左侧是一个机型列表,右侧是机型信息及其他信息,点击左侧的机型,右边跟着变为对应的信息. 由于右侧信息比较复杂,还有进度条什么的,所以如果右侧只用一 ...

  10. git本地及远程分支回退

    1. git本地版本回退 Git reset --hard commit_id(可用 git log –oneline 查看) 2. git远程版本回退 git push origin HEAD -- ...