此部分代码为基于opencv2的人脸识别系统(一)的具体代码,详细系统构成及各部分讲解请戳以下链接:
http://blog.youkuaiyun.com/u012679707/article/details/79510630
第一部分:main.cpp
/*
Project Name:FaceRecognition
Author:Lisa
Data:2017_12
Version:V1
Abstract:
the faceRecognition system includes 3 modules:
1.capture.cpp ->capture face Image and Detect face
2.train.cpp ->train face module
3.predict.cpp ->capture face image,face detection,face recognition
Statement:
You are free to use, change, or redistribute the code in any way you wish for
non-commercial purposes, but please maintain the name of the original author.
This code comes with no warranty(保证) of any kind.
*/
//#include"stdafx.h"
#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
#include<fstream> //包含ifstream
#include"opencv2/cvui/cvui.h"
#include"capture.hpp"
#include"train.hpp"
#include"predict.hpp"
#include<windows.h>
using namespace cv;
using namespace std;
//using namespace cvui;
#define WINDOW_NAME "Face Recognition System ByLISA"
// 采集到的图片保存地址
const string savePath="F:\\opencv_project\\faceRecognition\\ORL\\prePhoto\\1.pgm";
/******************************* main() ***************************************************************/
Mat Frame;
int main(int argc,char *argv[])
{
system("color 5E");
//Mat img=imread("lanyangyang.jpg");
namedWindow(WINDOW_NAME);
cvui::init(WINDOW_NAME);
Frame=Mat(320,500,CV_8UC3);
Frame = cv::Scalar(200,20,200); //颜色填充49, 52, 49
cvui::window(Frame,350,30,100,132,"predict photo");
cvui::window(Frame,350,165,100,132,"predict result");
while(1)
{
bool buttonCapture=cvui::button(Frame,50,100,"Capture");
bool buttonTrain=cvui::button(Frame,50,130,"Train");
bool buttonPredict=cvui::button(Frame,50,160,"Predict");
if(buttonCapture) {
Mat capPhoto;
if(photoCapture(capPhoto)) cvui::text(Frame, 150, 100, "capture is sucessful!");
else cvui::text(Frame, 150, 100, "capture failed!");
}
if(buttonTrain) {
if(train()) cvui::text(Frame, 150, 130, "train is sucessful!");
else cvui::text(Frame, 150, 100, "train failed!");
}
if(buttonPredict) {
cvui::printf(Frame, 150, 160,0.4, 0x00ff00, "predict result is ");
Mat predictPhoto;//待识别照片
int predictResult;//预测结果
predict(predictPhoto,predictResult);
imwrite(savePath,predictPhoto);
cvui::printf(Frame, 150, 160,0.4, 0x00ff00, "predict result i