【opencv】基于opencv2的人脸识别系统(二)具体代码

这是一个关于基于OpenCV2实现人脸识别系统的博客,包括main.cpp、capture.cpp、train.cpp和predict.cpp四个部分的代码详细说明,链接指向了更多系统构成和各部分的详细解释。
摘要由CSDN通过智能技术生成

此部分代码为基于opencv2的人脸识别系统(一)的具体代码,详细系统构成及各部分讲解请戳以下链接:

http://blog.csdn.net/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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值