最近看人脸识别,用的orl库,看网上人脸识别的csv文件都是用python实现的,但是我也懒得装python环境,所以用c++实现了,虽然不难,也和大家分享一下。
顺便提下orl库下载地址,csdn下载有点慢。。。。
orl地址;http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html
代码实现:
#include<iostream>
#include<vector>
#include<io.h>
#include<fstream>
using namespace std;
void getFiles(string path, vector<string>& files)
{
//文件句柄
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
//如果是目录,迭代之
//如果不是,加入列表
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
}
else
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
int main(){
char* filepath = "F:\\opencv\\DATA\\orl";
vector<string> files;
ofstream off("csv.txt",ios::out);
getFiles(filepath,files);
char str[30];
int size = files.size();
for (int i = 1; i < size; i++){
off << files[i].c_str();
off << "\n";
}
off.close();
return 0;
}
效果图