資源簡介
主要實現(xiàn)人臉疲勞檢測,應(yīng)用方面很廣,比如貨運司機(jī)的預(yù)警系統(tǒng),火車預(yù)警系統(tǒng)等等
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?“Dlib.h“
#include?“FatigueDetect.h“
#include?“facedetect-dll.h“
using?namespace?dlib;
using?namespace?std;
using?namespace?cv;
void?ImageTest();
void?VideoTest();
void?VideoTest2();
void?VideoTest3();
int?main()
{
VideoTest2();
//VideoTest3();
return?0;
}
void?ImageTest()
{
long?start?end;
setUseOptimized(true);
char?img_file[]?=?“E:\\WorkStation\\Project\\DlibTest\\x64\\Debug\\image_0026.png“;
char?landmark_file[]?=?“E:\\WorkStation\\Source\\shape_predictor_68_face_landmarks.dat“;
Mat?img?=?imread(img_file?CV_BGR2GRAY);
frontal_face_detector?detector?=?get_frontal_face_detector();
shape_predictor?sp;
deserialize(landmark_file)?>>?sp;
array2d?arrImg;
load_image(arrImg?img_file);
start?=?clock();
std::vector?dets?=?detector(arrImg);
for?(unsigned?long?j?=?0;?j? {
full_object_detection?shape?=?sp(arrImg?dets[j]);
for?(unsigned?long?i?=?0;?i? {
point?pt?=?shape.part(i);
int?x?=?pt.x();
int?y?=?pt.y();
line(img?Point(pt.x()?pt.y())?Point(pt.x()?pt.y())?Scalar(0?0?255)?2);
}
}
end?=?clock();
printf(“%ld\n“?end?-?start);//單位:毫秒
imshow(“img“?img);
waitKey();
}
void?VideoTest()
{
char?landmark_file[]?=?“shape_predictor_68_face_landmarks.dat“;
Ptr?cascade?=?makePtr(“l(fā)bpcascade_frontalface_improved.xml“);
VideoCapture?cap(0);
if?(!cap.isOpened())
{
std::cout?<“open?failed“?< return;
}
Mat?frame;
Mat?merge;
Mat?convermat;
std::vector?faces;
frontal_face_detector?detector?=?get_frontal_face_detector();
shape_predictor?sp;
deserialize(landmark_file)?>>?sp;
clock_t?start?end;
while?(true)
{
cap?>>?frame;
if?(frame.empty())
{
std::cout<“frame?is?empty“?< break;
}
start?=?clock();
std::vector?splitframe;
split(frame?splitframe);
for?(int?i?=?0;?i?ame.size();?i++)
{
splitframe[i].convertTo(splitframe[i]splitframe[i].type()1.520);
equalizeHist(splitframe[i]?splitframe[i]);
}
cv::merge(splitframe?merge);
imshow(“equ“merge);
cv_image?arrImg(merge);
std::vector?dets?=?detector(arrImg);
for?(unsigned?long?j?=?0;?j? {
full_object_detection?shape?=?sp(arrImg?dets[j]);
for?(unsigned?long?i?=?0;?i? {
point?pt?=?shape.part(i);
int?x?=?pt.x();
int?y?=?pt.y();
circle(frame?Point(pt.x()?pt.y())?0.2?Scalar(0?0?255)?2);
}
}
end?=?clock();
c
評論
共有 條評論