opencv实现遍历文件夹下所有文件
前言
最近需要将视频数据集中的每个视频进行分割,分割成等长的视频片段,前提是需要首先遍历数据集文件夹中的所有视频。
实现
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实现遍历文件夹下所有文件的更多相关文章
- C#遍历文件夹下所有文件
FolderForm.cs的代码如下: using System; using System.Collections.Generic; using System.Diagnostics; using ...
- python (9)统计文件夹下的所有文件夹数目、统计文件夹下所有文件数目、遍历文件夹下的文件
命令:os 用到的:os.walk os.listdir 写的爬虫爬的数据,但是又不知道进行到哪了,于是就写了个脚本来统计文件的个数 #统计 /home/dir/ 下的文件夹个数 import o ...
- PHP遍历文件夹下的文件和获取到input name的值
<?php$dir = dirname(__FILE__); //要遍历的目录名字 ->当前文件所在的文件夹//$dir='D:\PHP\wamp\www\admin\hosts\admi ...
- java中File类应用:遍历文件夹下所有文件
练习: 要求指定文件夹下的所有文件,包括子文件夹下的文件 代码: package 遍历文件夹所有文件; import java.io.File; public class Test { public ...
- c bash 代码遍历文件夹下所有文件
用C代码.bash实现代码遍历文件夹下所有文件 递归方式实现如下: void listdir(char *path) { DIR *ptr_dir; struct dirent *dir_entry; ...
- PHP使用glob方法遍历文件夹下所有文件
PHP使用glob方法遍历文件夹下所有文件 遍历文件夹下所有文件,一般可以使用opendir 与 readdir 方法来遍历.<pre><?php$path = dirname(__ ...
- 利用shell脚本或者php移动某个文件夹下的文件到各自的日期组成的目录下
背景是这样的:网站一开始访问量比较小,大家就把所有的图片文件上传到一个目录下(比如是/data/images/).后来访问量大了,图片也多了,这样就影响读取效率.所以有个这样的需求,把这些个图片文件移 ...
- FILE文件删除操作(删除指定文件夹下所有文件和文件夹包括子文件夹下所有文件和文件夹),就是删除所有
2018-11-05 19:42:08开始写 选择 删除 1.FileUtils.java类 import java.io.File;//导入包 import java.util.List;//导入 ...
- python 替换 文件夹下的 文件名称 及 文件内容
示例效果: 1.替换某文件夹下的 文件夹及子文件夹 的名称 由OldStrDir 变为 NewStrDir: 2.替换某文件夹下的 文件夹及子文件夹 下 所有的文件的名称 由OldStrFile 变为 ...
随机推荐
- Redis的介绍
REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统. Redis是一个开源的使用ANSI C语言编写.遵守B ...
- 雷林鹏分享:C# 集合(Collection)
C# 集合(Collection) 集合(Collection)类是专门用于数据存储和检索的类.这些类提供了对栈(stack).队列(queue).列表(list)和哈希表(hash table)的支 ...
- illumina phix
PhiX Control v3 is a reliable, adapter-ligated library used as a control for Illumina sequencing run ...
- English trip -- VC(情景课)5 C It's on Main Street 在主街上
Grammar focus 语法点: on, 在...上 next to , 旁边,周围 aross from , 对面 between 在...之间 in front of 在…前面 ...
- Jersey 2.x 分支 Java SE 兼容性
直到 Jersey 2.6 版本,Jersey 将会兼容 Java SE 6.这个情况将会在在 Jersey 2.7 的版本有所改变. 直到 Jersey 版本 2.25x, 所有的 Jersey 的 ...
- MySQL缓存机制
对MySql查询缓存及SQL Server过程缓存的理解及总结 一.MySql的Query Cache 1.Query Cache MySQL Query Cache是用来缓存我们所执行的SELE ...
- 根据Request获取真实客户端IP
转载:http://www.cnblogs.com/icerainsoft/p/3584532.html 在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr() ,这 ...
- hibernate一级缓存和二级缓存的区别
http://blog.csdn.net/defonds/article/details/2308972 缓存是介于应用程序和物理数据源之间,其作用是为了降低应用程序对物理数据源访问的频次,从而提高了 ...
- kill di/dia out 1
1● di 使~ 变成 :两个,两, 2● dia 穿过,二者之间
- UVALive 4764 dp
DES: 这是一个新的游戏.给你一套牌.编号从1到100000.正常来说.你手中的牌和这次翻的牌是一样的,就会加一分.但是.如果是999的话.加三分.所以问你最大的分是多少. 貌似是简单的DP吧.(D ...