您的位置:首页 > 编程语言 > C语言/C++

浅理解C++ 人脸识别系统的实现

2020-04-28 12:04 1956 查看

机器学习

  • 机器学习的目的是把数据转换成信息。
  • 机器学习通过从数据里提取规则或模式来把数据转成信息。

人脸识别

  • 人脸识别通过级联分类器对特征的分级筛选来确定是否是人脸。
  • 每个节点的正确识别率很高,但正确拒绝率很低。
  • 任一节点判断没有人脸特征则结束运算,宣布不是人脸。
  • 全部节点通过,则宣布是人脸。

工业上,常用人脸识别技术来识别物体。

基于深度学习的人脸识别系统,一共用到5个开源库:OpenCV(计算机视觉库)、Caffe(深度学习库)、Dlib(机器学习库)、libfacedetection(人脸检测库)、cudnn(gpu加速器)。

用到一个开源的深度学习模型:VGG model。

#include "opencv2/core/core.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

string face_cascade_name = "haarcascade_frontalface_alt.xml";
CascadeClassifier face_cascade;
string window_name = "人脸识别";

void detectAndDisplay( Mat frame );

int main( int argc, char** argv ){
Mat image;
image = imread( argv[1]);

if( argc != 2 || !image.data ){
printf("[error] 没有图片\n");
return -1;
}

if( !face_cascade.load( face_cascade_name ) ){
printf("[error] 无法加载级联分类器文件!\n");
return -1;
}

detectAndDisplay(image);

waitKey(0);
}

void detectAndDisplay( Mat frame ){
std::vector<Rect> faces;
Mat frame_gray;

cvtColor( frame, frame_gray, CV_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );

face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

for( int i = 0; i < faces.size(); i++ ){
Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
}

imshow( window_name, frame );
}

参考文章:https://www.geek-share.com/detail/2564549480.html

到此这篇关于浅理解C++ 人脸识别系统的实现的文章就介绍到这了,更多相关C++ 人脸识别内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C++ 人脸识别
相关文章推荐