最近看人臉識別,用的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;
}
效果圖