opencv批量导入文件夹中图片和保存处理后的图片
**
使用环境
**:在工程中需要批量处理图像时,需要对文件夹中图片进行批量处理。简化版本
使用opencv中的glob函数:
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
//读取文件地址
String img_file = "C:\\Users\\tudejiang\\Desktop\\超声图像VOC格式标准数据集201911\\VOC2007\\JPEGImages\\*.jpg";
//保存文件地址
string save_img_file = "C:\\Users\\tudejiang\\Desktop\\超声图像VOC格式标准数据集201911\\VOC2007\\save1\\";
//保存图片全名
string savedfilename;
//存储读取文件地址图片名
vector<String> image_files;
//存储图片函数
glob(img_file , image_files);
for (int i = 0; i < image_files.size(); i++)
{
cout << image_files[i] << endl;
Mat src = imread(image_files[i]);
//统计图片有占据多少字节
int num = img_file.size();
//从图片全名称后截取末尾图片名称,和图片存储地址链接
savedfilename = save_img_file + image_files[i].substr(num-5);
cout << savedfilename << endl;
imwrite(savedfilename, src);
}
waitKey(0);
return 0;
}