淺理解C++ 人臉識別系統(tǒng)的實現(xiàn)
機器學(xué)習(xí)
- 機器學(xué)習(xí)的目的是把數(shù)據(jù)轉(zhuǎn)換成信息。
- 機器學(xué)習(xí)通過從數(shù)據(jù)里提取規(guī)則或模式來把數(shù)據(jù)轉(zhuǎn)成信息。
人臉識別
- 人臉識別通過級聯(lián)分類器對特征的分級篩選來確定是否是人臉。
- 每個節(jié)點的正確識別率很高,但正確拒絕率很低。
- 任一節(jié)點判斷沒有人臉特征則結(jié)束運算,宣布不是人臉。
- 全部節(jié)點通過,則宣布是人臉。
工業(yè)上,常用人臉識別技術(shù)來識別物體。
基于深度學(xué)習(xí)的人臉識別系統(tǒng),一共用到5個開源庫:OpenCV(計算機視覺庫)、Caffe(深度學(xué)習(xí)庫)、Dlib(機器學(xué)習(xí)庫)、libfacedetection(人臉檢測庫)、cudnn(gpu加速器)。
用到一個開源的深度學(xué)習(xí)模型: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] 無法加載級聯(lián)分類器文件!\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
到此這篇關(guān)于淺理解C++ 人臉識別系統(tǒng)的實現(xiàn)的文章就介紹到這了,更多相關(guān)C++ 人臉識別內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
c++ STL set_difference set_intersection set_union 操作
這篇文章主要介紹了c++ STL set_difference set_intersection set_union 操作,需要的朋友可以參考下2017-03-03

