#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
char fileName[50]; //读取图片的路径
char fileName1[50];//保存图片的路径
Mat src,dst;
for (int i = 1; i < 3; i++) {
sprintf_s(fileName, "E:\\Download\\Images\\%d.jpg", i); //读取图片的路径
sprintf_s(fileName1, "E:\\Download\\Images\\xpx\\%d.jpg", i); //保存图片的路径
src = imread(fileName); //从路径中读取图片
//**********************************************
//操作,这里简单转化为灰度图,仅做展示
cvtColor(src, dst,COLOR_BGR2GRAY);
//****************************************************
imwrite(fileName1, dst); //保存处理后的图片
}
waitKey(0); //单位毫秒,0表示永远
return 0;
}
参考二,指定路径下读取,并显示
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
class Ve {
public:
vector<Mat> ReadImage(cv::String pattern);
};
int main()
{
cv::String pattern = "E:\\Download\\Images\\*.jpg";
Ve ve;
vector<Mat> img = ve.ReadImage(pattern);
return 0;
}
vector<Mat> Ve::ReadImage(cv::String pattern)
{
vector<cv::String> fn;
glob(pattern, fn, false);
vector<Mat> images;
size_t count = fn.size(); //number of png files in images folder
for (size_t i = 0; i < count; i++)
{
images.emplace_back(cv::imread(fn[i]));
imshow("img", imread(fn[i]));
waitKey(0);
}
return images;
}
|