前言

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

实现

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. [ios]安装CocoaPods及使用详解

    最新 macOS Sierra 10.12.3 安装CocoaPods及使用详解 http://www.jianshu.com/p/b64b4fd08d3c CocoaPods的安装以及遇到的坑 ht ...

  2. 2018年全国多校算法寒假训练营练习比赛(第一场)E 恋与程序员

    https://www.nowcoder.com/acm/contest/67/E 思路: dfs 代码: #include<bits/stdc++.h> using namespace ...

  3. Codeforces 260B - Ancient Prophesy

    260B - Ancient Prophesy 思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部 ...

  4. vue.js选择if(条件渲染)详解

    vue.js选择if(条件渲染)详解 一.总结 一句话总结: v-if <!DOCTYPE html> <html lang="en"> <head& ...

  5. Linux-Load Average解析

    load Average 转自:http://www.blogjava.net/sliverfancy/archive/2013/04/17/397947.html 1.1:什么是Load?什么是Lo ...

  6. LeetCode--108--将有序数组转化为二叉搜索树

    问题描述: 将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1. 示例: 给定有序数组: [-10 ...

  7. 20170706wdVBA正则表达式提取题目

    Public Sub GetContents() Dim Reg As Object Dim Matches As Object Dim OneMatch As Object Dim Index As ...

  8. hdu2955(概率DP)

    The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually g ...

  9. hdu2510 爆搜+打表

    符号三角形 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  10. Socket编程基础篇

    Socket又称"套接字",应用程序通常通过“套接字”向网络发生请求或者应答网络请求. Socket和ServerSocket类库位于java.net包中,ServerSocket ...