#include <opencv2/opencv.hpp>
#include <iostream>
#include <opencv2/face.hpp>
using namespace std;
using namespace cv;
using namespace cv::face;
char wintitle[40] = {};
int main(int argc, char** argv) {
string filename = string("D:/Project/image/data_faces/1.csv");
ifstream file(filename.c_str(), ifstream::in);
if (!file) {
printf("colud not load file correctly...\n");
return -1;
}
string line, path, classlabel;
vector<Mat> images;
vector<int> labels;
char separator = ';';
while (getline(file, line))
{
stringstream liness(line);
getline(liness, path, separator);
getline(liness, classlabel);
if (!path.empty() && !classlabel.empty()) {
printf("path: %s\n", path.c_str());
images.push_back(imread(path ,0));
labels.push_back(atoi(classlabel.c_str()));
}
}
if (images.size() < 1 || labels.size() < 1) {
printf("invalid image path...\n");
return -1;
}
int height = images[0].rows;
int width = images[0].cols;
printf("height:%d,width:%d\n", height, width);
Mat testSample = images[images.size() - 1];
int testLabel = labels[labels.size() - 1];
images.pop_back();
labels.pop_back();
Ptr<EigenFaceRecognizer> model = EigenFaceRecognizer::create();
model->train(images, labels);
int predictedLabel = model->predict(testSample);
printf("actual label:%d,predict label:%d\n", testLabel, predictedLabel);
Mat eigenvalues = model->getEigenValues();
Mat eigenvector = model->getEigenVectors();
Mat mean = model->getMean();
Mat meanFace = mean.reshape(1, height);
Mat dst;
if (meanFace.channels() == 1) {
normalize(meanFace, dst, 0, 255, NORM_MINMAX, CV_8UC1);
}
else if (meanFace.channels() == 3) {
normalize(meanFace, dst, 0, 255, NORM_MINMAX, CV_8UC3);
}
imshow("Mean Face", dst);
for (int i = 0; i < min(10, eigenvalues.cols); i++) {
Mat ev = eigenvalues.col(i).clone();
Mat grayscale;
Mat eigenFace = ev.reshape(1, height);
if (eigenFace.channels() == 1) {
normalize(eigenFace, grayscale, 0, 255, NORM_MINMAX, CV_8UC1);
}
else if (eigenFace.channels() == 3) {
normalize(eigenFace, grayscale, 0, 255, NORM_MINMAX, CV_8UC3);
}
Mat colorface;
applyColorMap(grayscale, colorface, COLORMAP_BONE);
sprintf_s(wintitle, "eigenface_%d", i);
imshow(wintitle, colorface);
}
waitKey(0);
return 0;
}
OpenCV人脸识别中出现EigenFaceRecognizer::create()无法解析,请问大神们怎么解决?编译环境VS2019社区版+Opencv3413