1. 程式人生 > >OpenCV3.4.1 實現人臉識別

OpenCV3.4.1 實現人臉識別

參考連結:

測試程式碼

#include <opencv2/opencv.hpp>
#include <opencv2/face.hpp>

using namespace std;
using namespace cv;
using namespace cv::face;


int main()
{
	// Create a FaceRecognizer:
	Ptr<FaceRecognizer> model = EigenFaceRecognizer::create();
	model->read("D:\\OpenCV\\MyFacePCAModel.xml");

	cout << "read model ok!" << endl;

	// Do your initialization here (create the cv::FaceRecognizer model) ...
	// ...
	// Read in a sample image:
	Mat img = imread("D:\\datasets\\att_faces\\s2\\1.pgm", CV_LOAD_IMAGE_GRAYSCALE);
	// And get a prediction from the cv::FaceRecognizer:
	int predicted = model->predict(img);
	cout << "predicted result is : "<< predicted << endl;

	waitKey(0);
	system("pause");
    return 0;
}