#include "fatiguedetect.h"
// 常量定义
const double close_standard = 0.45;
const int eye_l_len = 60;
// 判断状态的类
class JudgeCondition : public QObject {
Q_OBJECT
public:
explicit JudgeCondition(QObject *parent = nullptr) : QObject(parent), condition(0), heavy_flag(0) {};
void judge(std::deque<int> &left_eye_l, std::deque<int> &right_eye_l)
{
int left_sum = std::accumulate(left_eye_l.begin(), left_eye_l.end(), 0);
int right_sum = std::accumulate(right_eye_l.begin(), right_eye_l.end(), 0);
if (left_sum == eye_l_len && right_sum == eye_l_len) {
++heavy_flag;
if (heavy_flag > 100) {
condition = 3;
} else {
condition = 2;
}
} else {
heavy_flag = 0;
condition = 1;
}
emit sendCondition(condition);
};
signals:
void sendCondition(int);
private:
int condition; // 状态:0=图像缺失 1=清醒 2=疲劳 3=重度疲劳
int heavy_flag; // 重度疲劳标志位
};
FatigueDetect::FatigueDetect(QObject *parent) : QObject(parent),
noImageFlag(0),
noImage(0)
{
cout << "[INFO] loading facial landmark predictor..." << endl;
dlib::deserialize("./model.dat") >> predictor; //是直接调试运行,则在build文件夹内;如果为release则与.exe在同一文件夹内
detector = dlib::get_frontal_face_detector();
}
cv::Mat FatigueDetect::detect(cv::Mat frame)
{
std::vector<std::vector<cv::Point>> pos;
cv::Mat resized_frame;
cv::resize(frame, resized_frame, cv::Size(720, 720 * frame.rows / frame.cols));
cv::Mat gray;
// cv::cvtColor(resized_frame, gray, cv::COLOR_BGR2GRAY);
cv_image<bgr_pixel> dlib_img(resized_frame);
std::vector<dlib::rectangle> rects = detector(dlib_img, 0); //这里放入detector的必须是dlib类型参数,不能是cv::Mat,不报错,但编译时出“问题”
if (rects.size() == 0)
{
noImage = 1;
emit noSignal(noImageFlag);
}
for (dlib::rectangle rect : rects) //for(类型 变量名称 : 容器/数组等内容)
{
noImage = 0;
dlib::full_object_detection shape = predictor(dlib_img, rect);
std::vector<cv::Point> pos_;
for (int i = 36; i <= 41; i++) //左眼关键点标识
{
cv::Point point(shape.part(i).x(), shape.part(i).y());
pos_.push_back(point);
}
for (int i = 42; i <= 47; i++) //右眼关键点标识
{
cv::Point point(shape.part(i).x(), shape.part(i).y());
pos_.push_back(point);
}
pos.push_back(pos_);
draw_point_and_line(pos_, resized_frame);
}
cv::Mat resized_back_frame;
cv::resize(resized_frame, resized_back_frame, cv::Size(frame.cols, frame.rows));
return resized_back_frame;
}
void FatigueDetect::draw_point_and_line(std::vector<cv::Point> pos_, cv::Mat &image)
{
int linewidth = 1;
for (int i = 0; i < 5; i++)
{
cv::line(image, pos_[i], pos_[i + 1], cv::Scalar(0, 255, 0), linewidth);
}
cv::line(image, pos_[0], pos_[5], cv::Scalar(0, 255, 0), linewidth);
for (int i = 6; i < 11; i++)
{
cv::line(image, pos_[i], pos_[i + 1], cv::Scalar(0, 255, 0), linewidth);
}
cv::line(image, pos_[6], pos_[11], cv::Scalar(0, 255, 0), linewidth);
for (cv::Point point : pos_)
{
cv::circle(image, point, linewidth, cv::Scalar(255, 0, 0), -1);
}
}

wang_chao118
- 粉丝: 1978
最新资源
- 广东省电子商务认证有限公司.ppt
- 自动化考试试题.doc
- 2023年师德师风法律法规网络竞赛题.doc
- 三G网络互操作优化原则和优化方案.doc
- 人工智能及其应用实验指导书.doc
- 医学西门子PLC故障诊断简易教程专题.ppt
- 小学生计算机辅助教学系统试题.doc
- 游戏开发团队建设ppt免费.pptx
- C语言期末试卷1.pdf
- 2022年电大C语言程序设计作业答案剖析.doc
- 有关软件工程的实习报告.docx
- 网络直销模式案例分析.ppt
- 项目管理班子配备.doc
- 论网络跳蚤市场对电子商务发展的影响.docx
- 某公司网络广告策划书.doc
- 基于单片机的十字路口交通信号灯控制-毕业设计论文.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


