因opencv directory已经不能使用,手写opencv contrib实现Directory类

因opencv directory已经不能使用,手写opencv contrib实现Directory类


C++读取一个文件夹下的所有文件并不方便,可以利用opencv
opencv中有一个工具类Directory:它可以遍历对应文件夹下的所有文件,帮助读取文件夹下的所有文件名。但是在opencv高版本中,contrib已经被摘出来了,导致directory不能使用。
给出方法:
自己写一个contrib.h文件,放同目录下,然后#include"contrib.h"

contrib.h内容如下:

#ifndef __OPENCV_CONTRIB_HPP__
#define __OPENCV_CONTRIB_HPP__

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"

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);
};
#endif

在cpp文件下写using namespace cv;
即可直接用Directory,例如:

Directory dir;
    vector<string> fileNames = dir.GetListFiles(dirPath,"*.ply",false);

参考链接:
链接: CSDN下载.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值