level 1
#include "training.h"
training::training(string txt_path, vector<Mat> images, vector<int> sig)
{
read_CSV(txt_path, images, sig);
int a = images.size();
Ptr<EigenFaceRecognizer> PCA = EigenFaceRecognizer::create();
PCA->train(images, sig);
PCA->save("PCA_SpecialFaceModel.xml");
cout << "train.创建脸模型ok" << endl;
}
void training::read_CSV(string txt_path,vector<Mat> images, vector<int> sig)
{
string lines, path_name, lable;
cout << txt_path<<endl;
ifstream file(txt_path,ifstream::in);
if (!file.is_open())
{
string error_message = "error ";
cout << error_message;
}
int n = 0;
while (getline(file, lines))
{
int pos = lines.find(';');
path_name = lines.substr(0, pos);
lable = lines.substr(pos+1, lines.length());
if (!path_name.empty() && !lable.empty())
{
cout << path_name << endl;
cout << lable << endl;
Mat temp=imread(path_name);
//imshow("ok", temp);
if (temp.data != 0)
{
//images.push_back(imread(path_name, 0));
images.push_back(temp);
sig.push_back(stoi(lable));//把string转换成int
}
}
cout << n + 1<< endl;
n++;
}
}
2020年03月28日 12点03分