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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

进击的小尧好程序员   2020-03-22 我要评论

机器学习

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

 

人脸识别

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

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

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

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

 1 #include "opencv2/core/core.hpp"
 2 #include "opencv2/objdetect/objdetect.hpp"
 3 #include "opencv2/highgui/highgui.hpp"
 4 #include "opencv2/imgproc/imgproc.hpp"
 5 
 6 #include <iostream>
 7 #include <stdio.h>
 8 
 9 using namespace std;
10 using namespace cv;
11 
12 string face_cascade_name = "haarcascade_frontalface_alt.xml";
13 CascadeClassifier face_cascade;
14 string window_name = "人脸识别";
15 
16 void detectAndDisplay( Mat frame );
17 
18 int main( int argc, char** argv ){
19     Mat image;
20     image = imread( argv[1]);
21 
22     if( argc != 2 || !image.data ){
23         printf("[error] 没有图片\n");
24         return -1;
25     }
26 
27     if( !face_cascade.load( face_cascade_name ) ){ 
28         printf("[error] 无法加载级联分类器文件!\n");
29         return -1; 
30     }
31 
32     detectAndDisplay(image);
33 
34     waitKey(0);    
35 }
36 
37 void detectAndDisplay( Mat frame ){
38     std::vector<Rect> faces;
39     Mat frame_gray;
40 
41     cvtColor( frame, frame_gray, CV_BGR2GRAY );
42     equalizeHist( frame_gray, frame_gray );
43 
44     face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
45 
46     for( int i = 0; i < faces.size(); i++ ){
47         Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
48         ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
49     }
50 
51     imshow( window_name, frame );
52 }

初次接触人脸识别编程,感谢一位博主的文章给的参考...https://www.cnblogs.com/justany/archive/2012/11/22/2781552.html

这篇文章讲的比较透彻

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们