C++实现人脸识别csv文件的写入(加labels)

来源:互联网 发布:php安装教程 编辑:程序博客网 时间:2024/05/18 01:03

前面也写了一个csv是没有加label的(http://blog.csdn.net/u013812682/article/details/52013074),
上次写完因为有点事所以没看这块,才发现少加了label,所以在这里补上
orl下载地址:http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html
代码:

#include<iostream>#include<vector>#include<io.h>#include<fstream>using namespace std;ofstream off("csv.txt", ios::out);vector<int> number;int num = 0;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);                    num++;                }            }            else            {                files.push_back(p.assign(path).append("\\").append(fileinfo.name));                number.push_back(num);            }        } while (_findnext(hFile, &fileinfo) == 0);        _findclose(hFile);    }}int main(){    char* filepath = "F:\\opencv\\DATA\\orl";    vector<string> files;    getFiles(filepath,files);    char str[30];    int size = files.size();    for (int i = 1; i < size; i++){        off << files[i].c_str();        off << " ";        off << number[i];        off << "\n";    }    off.close();    return 0;}

这里写图片描述

0 0
原创粉丝点击