#include #include #include <iostream> #include <stdio.h> #include #include using namespace cv; using namespace std; const char *facerecAlgorithm = "FaceRecognizer.Fisherfaces"; int main() { string facerecAlgorithm = "FaceRecognizer.Fisherfaces"; Ptr<facerecognizer> model; // Make sure the "contrib" module is dynamically loaded at runtime. // Requires OpenCV v2.4.1 or later (from June 2012), otherwise the FaceRecognizer will not compile or run! bool haveContribModule = initModule_contrib(); if (!haveContribModule) { cerr << "ERROR: The 'contrib' module is needed for FaceRecognizer but has not been loaded into OpenCV!" << endl; exit(1); } else { cout << "\ncontrib module is successfully loaded" << std::endl; } model = Algorithm::create<facerecognizer>(facerecAlgorithm); if (model.empty()) { cerr << "ERROR: The FaceRecognizer [" << facerecAlgorithm; cerr << "] is not available in your version of OpenCV. "; cerr << "Please update to OpenCV v2.4.1 or newer." << endl; exit(1); } else { cout << "\nFisherFaceRecognizer is successfully loaded" << std::endl; } cout << "\nFisherFaceRecognizer training starting......" << std::endl; // holds images and labels vector<mat> images; vector<int> labels; // images for first person images.push_back(imread("1.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0); images.push_back(imread("3.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0); images.push_back(imread("5.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0); // images for second person images.push_back(imread("2.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1); images.push_back(imread("4.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1); // This is the common interface to train all of the available cv::FaceRecognizer // implementations model->train(various_images, labels); cout << "\nFisherFaceRecognizer training finished......" << std::endl; return 0; }</int></mat></facerecognizer></facerecognizer></stdio.h></iostream>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)