通过后缀名遍历文件夹内的图像
来源:互联网 发布:mac 上给iphone传照片 编辑:程序博客网 时间:2024/06/14 00:01
#ifndef FILELOCATOR_H#define FILELOCATOR_H#include <stdio.h>#include <cstdlib>#include <iostream>#include <string.h>#include <fstream>#include <dirent.h>#include <vector>#include <algorithm>using namespace std;class FileLocator{public: FileLocator(); vector<string> listFile(string path, string extension);private:};#endif // FILELOCATOR_H
#include "filelocator.h"using namespace std;bool compareNoCase (string first, string second){ int i=0; while ((i < first.length()) && (i < second.length())) { if (tolower (first[i]) < tolower (second[i])) return true; else if (tolower (first[i]) > tolower (second[i])) return false; i++; } if (first.length() < second.length()) return true; else return false;}FileLocator::FileLocator(){}vector<string> FileLocator::listFile(string path, string extension) { vector<string> files; DIR *pDIR; struct dirent *entry; if( pDIR=opendir(path.c_str()) ) { while(entry = readdir(pDIR)) { if( strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0 && strcmp(entry->d_name+strlen(entry->d_name)-strlen(extension.c_str()),extension.c_str()) == 0 ) { if(path[strlen(path.c_str())-1] == '/') files.push_back(string(path) + string(entry->d_name)); else files.push_back(string(path) + string("/") + string(entry->d_name)); } } closedir(pDIR); } std::sort(files.begin(), files.end(),compareNoCase); return files;}
#include <opencv2/opencv.hpp>#include "filelocator.h"using namespace cv;using namespace std;#define EXT ".png"int main(){string pattern = "F:\\Test\\test";vector<string> fn;FileLocator FL;fn = FL.listFile(pattern, EXT);size_t count = fn.size();cout << "一共有" << count << "张图像需要处理!" << endl;for (int i = 0; i < count; i++){Mat image = imread(fn[i]);imshow("Source", image);waitKey(30);}cout << "处理完成!\n" << endl;return 0;}
阅读全文
0 0
- 通过后缀名遍历文件夹内的图像
- Shell遍历文件夹删除指定后缀名的文件
- 删除指定文件夹内指定后缀名文件
- 遍历文件夹内的文件 实例代码
- 遍历文件夹内的所有文件
- matlab 遍历图像文件夹
- MATLAB读取文件夹及其所有子文件夹内的图像
- python自动化,读取文件夹内所有文件名字,并做简单的后缀名匹配
- oject-c 代码 遍历目录 遍历文件夹 匹配后缀名
- Win10中使用CMD命令遍历文件夹去除多余后缀名
- 【转】遍历文件夹内的所有文件和子文件
- PHP递归遍历指定文件夹内的文件
- 基于MFC的OpenCV显示文件夹内图像
- Matlab代码-遍历文件夹下所有指定格式的图像
- 文件夹图标后缀名变成.ink的解决办法
- PHP重命名文件夹下的文件后缀名
- java通过file批量修改文件夹内的文件名称
- iOS 通过文件的修改时间遍历整个文件夹
- HTML5--纯CSS3实现的tab标签切换
- QQ聊天机器人--基于酷Q写的插件
- 初识JavaScript
- 【Scikit-Learn 中文文档】使用 scikit-learn 介绍机器学习
- 深入理解Android音视频同步机制(一)概述
- 通过后缀名遍历文件夹内的图像
- 支付宝sdk集成
- 我与Python初接触
- 风控是如何运用手机运营商数据
- 【Scikit-Learn 中文文档】机器学习: scikit-learn 中的设置以及预估对象
- Python实现Pat 1013. Battle Over Cities (25)
- 刷系统
- hdoj-2222Keywords Search(AC自动机)
- 机器学习总结(三)——SVM