机器学习
人脸识别
工业上,常用人脸识别技术来识别物体。
基于深度学习的人脸识别系统,一共用到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.cnblogs.com/justany/archive/2012/11/22/2781552.html
到此这篇关于浅理解C++ 人脸识别系统的实现的文章就介绍到这了,更多相关C++ 人脸识别内容请搜索呐喊教程以前的文章或继续浏览下面的相关文章希望大家以后多多支持呐喊教程!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。