原理:1.先获取文件夹中图片的名称。
2.再通过图片地址和名称读取图片。
#include <iostream>
using namespace std;
#include <opencv2\opencv.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\contrib\contrib.hpp>
using namespace cv;
int main()
{
string dir_path = "E:\\桌面\\图片压缩\\";
Directory dir;
vector<string> fileNames = dir.GetListFiles(dir_path, "*.jpg", false);
for(int i = 0; i < fileNames.size(); i++)
{
//get image name
string fileName = fileNames[i];
string fileFullName = dir_path + fileName;
cout<<"File name:"<<fileName<<endl;
cout<<"Full path:"<<fileFullName<<endl;
//load image
Mat img = imread(fileFullName);
}
WaitKey(0);
return 0;
}