我所用的数据库是在D:\database\\000到D:\database\\142的文件夹下的jpg文件,读者可以根据自己的需要修改部分代码即可使用。
#include <iostream>
#include <stdio.h>
#include <opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <highgui.h>
#include<vector>
#include<string>
#include <windows.h>
//using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
Mat frame;
Directory dir;
//连续读取文件的方法
for (int i = 0; i < 142; i++)
{
string path1 = "D:\\database\\";
char tmpC[255];
sprintf(tmpC, "%d%d%d", (int)(i / 100), (int)((i % 100) / 10), (int)(i % 10));
path1 += tmpC;
string exten1 = "*.jpg";
vector<string> filenames = dir.GetListFiles(path1, exten1, false);
int size = filenames.size();
for (int j = 0; j < size; j++)
{
//cout << filenames[j] << endl;
frame = imread(path1 +"\\"+ filenames[j]);
;
savepath += tmpC;
char tmpC2[255]; sprintf(tmpC2, "%d%d", (int)((j % 100) / 10), (int)(j % 10));
savepath += "img"; savepath += tmpC2;
/////////////
if (frame.empty())
{
fprintf(stderr, "Can not load the image file.\n");
return -1;
}
imshow("The_facesbig", frame);
waitKey(1);
}
}
return 0;
}