当前位置: 首页 > news >正文

智慧车站车辆-基于YOLOv8与dlib的驾驶员疲劳检测系统 基于计算机视觉和深度学习技术的智能监测系统,能够实时检测驾驶员的疲劳状态,通过分析眼睛、嘴部等面部特征,及时发出疲劳预警,有效预防疲劳驾驶

智慧车站车辆-基于YOLOv8与dlib的驾驶员疲劳检测系统

本系统是一款基于计算机视觉和深度学习技术的智能监测系统,能够实时检测驾驶员的疲劳状态,通过分析眼睛、嘴部等面部特征,及时发出疲劳预警,有效预防疲劳驾驶带来的安全隐患

核心特性

  • 实时检测:支持摄像头实时监测和视频文件分析
  • 多维度分析:眼睛闭合、打哈欠、点头、眨眼频率等多指标综合评估
  • 行为识别(精度非常低,暂无解决办法):检测抽烟、打电话、喝水等危险驾驶行为
  • 数据可视化:实时显示疲劳指标和历史趋势分析
  • 报告生成:支持导出PDF和Excel格式的检测报告
  • 参数可调:灵活的检测参数配置,适应不同场景

主要功能:

  • 摄像头检测:使用电脑摄像头进行实时监测
  • 视频上传:上传预录制的视频文件进行分析
  • 实时指标显示:
  • EAR(眼睛纵横比):评估眼睛睁闭程度
  • MAR(嘴部纵横比):检测打哈欠
  • PERCLOS:眼睛闭合时间百分比
  • 眨眼频率:每分钟眨眼次数
  • 疲劳等级评估:
  • 清醒(0-30分)
  • 轻度疲劳(30-60分)
  • 重度疲劳(60-100分)
  • 行为检测:识别抽烟、打电话、喝水等危险行为

软件环境:
①Pycharm + Anaconda (或 VSCode + Anaconda)
②Python 3.9, OpenCV, PyQt5, ultralytics, torch1.9等

1
1

1

基于YOLOv8与dlib的驾驶员疲劳检测系统完整构建方案


一、项目核心信息表

项目详细内容
项目名称驾驶员疲劳检测系统
技术栈Python 3.9 + YOLOv8 + dlib + Flask/HTML前端
核心指标EAR(眼睛纵横比)、MAR(嘴部纵横比)、PERCLOS、眨眼频率、点头角度
疲劳等级清醒(0-30)、轻度疲劳(30-60)、重度疲劳(60-100)
检测方式摄像头实时监测、视频文件上传分析
辅助功能危险行为识别(抽烟/打电话/喝水)、数据可视化、报告生成、参数配置
开发环境PyCharm/VSCode + Anaconda,依赖OpenCV、ultralytics、dlib、Flask等

二、项目文件结构()

Driver Fatigue Detection System/ ├── data/ # 数据文件目录 ├── datasets/ # 数据集目录 ├── logs/ # 运行日志目录 ├── models/ # 模型权重文件 │ ├── yolov8-face.pt # 人脸检测模型 │ └── shape_predictor_68_face_landmarks.dat # dlib人脸关键点模型 ├── static/ # 前端静态资源(CSS/JS/图片) ├── templates/ # HTML前端页面 │ ├── index.html # 检测主页面 │ └── settings.html # 参数配置页面 ├── testfiles/ # 测试视频文件 ├── uploads/ # 上传视频存储目录 ├── app.py # Flask后端主程序(服务入口) ├── config.py # 系统配置文件 ├── database.py # 数据库操作(存储历史记录) ├── diagnose_camera.py # 摄像头诊断脚本 ├── download_models.py # 模型自动下载脚本 ├── fatigue_detector.py # 疲劳检测核心逻辑(EAR/MAR/PERCLOS计算) ├── quick_camera_test.py # 摄像头快速测试脚本 ├── report_generator.py # PDF/Excel报告生成工具 ├── requirements.txt # 环境依赖列表 ├── test_camera.py # 摄像头功能测试脚本 ├── test_db.py # 数据库功能测试脚本 ├── test_dlib.py # dlib关键点检测测试脚本 ├── video_processor.py # 视频文件处理脚本 ├── yolo_detector.py # YOLOv8人脸/危险行为检测脚本 └── 【必看】用户使用手册.md # 系统使用说明文档

三、环境准备与依赖安装

# 创建并激活虚拟环境conda create-nfatigue_detectpython=3.9conda activate fatigue_detect# 安装依赖pipinstall-rrequirements.txt

requirements.txt内容:

flask==2.0.1 opencv-python==4.5.5.62 ultralytics==8.0.200 torch==1.9.0 torchvision==0.10.0 dlib==19.22.0 numpy==1.21.6 pandas==1.3.5 openpyxl==3.0.9 reportlab==3.6.12

四、核心模块代码实现

1. 疲劳检测核心逻辑fatigue_detector.py

importdlibimportcv2importnumpyasnpfromscipy.spatialimportdistanceasdistclassFatigueDetector:def__init__(self,ear_threshold=0.21,mar_threshold=0.60,blink_frames=5,yawn_frames=5,perclos_window=60,perclos_threshold=0.35):# 加载dlib人脸关键点检测器self.detector=dlib.get_frontal_face_detector()self.predictor=dlib.shape_predictor("models/shape_predictor_68_face_landmarks.dat")# 疲劳检测参数self.ear_threshold=ear_threshold self.mar_threshold=mar_threshold self.blink_frames=blink_frames self.yawn_frames=yawn_frames self.perclos_window=perclos_window self.perclos_threshold=perclos_threshold# 状态变量self.eye_closed_frames=0self.yawn_frames_count=0self.perclos_history=[]self.fatigue_score=0defeye_aspect_ratio(self,eye):# 计算眼睛纵横比(EAR)A=dist.euclidean(eye[1],eye[5])B=dist.euclidean(eye[2],eye[4])C=dist.euclidean(eye[0],eye[3])ear=(A+B)/(2.0*C)returneardefmouth_aspect_ratio(self,mouth):# 计算嘴部纵横比(MAR)A=dist.euclidean(mouth[2],mouth[10])B=dist.euclidean(mouth[4],mouth[8])C=dist.euclidean(mouth[0],mouth[6])mar=(A+B)/(2.0*C)returnmardefdetect(self,frame):gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)faces=self.detector(gray)ear=1.0mar=0.0is_eye_closed=Falseis_yawn=Falseforfaceinfaces:landmarks=self.predictor(gray,face)landmarks=np.array([[p.x,p.y]forpinlandmarks.parts()])# 提取眼睛和嘴部关键点left_eye=landmarks[36:42]right_eye=landmarks[42:48]mouth=landmarks[48:68]# 计算EAR和MARear_left=self.eye_aspect_ratio(left_eye)ear_right=self.eye_aspect_ratio(right_eye)ear=(ear_left+ear_right)/2.0mar=self.mouth_aspect_ratio(mouth)# 检测闭眼ifear<self.ear_threshold:self.eye_closed_frames+=1ifself.eye_closed_frames>=self.blink_frames:is_eye_closed=Trueelse:self.eye_closed_frames=0# 检测打哈欠ifmar>self.mar_threshold:self.yawn_frames_count+=1ifself.yawn_frames_count>=self.yawn_frames:is_yawn=Trueelse:self.yawn_frames_count=0# 更新PERCLOSself.perclos_history.append(1ifis_eye_closedelse0)iflen(self.perclos_history)>self.perclos_window*30:# 假设30fpsself.perclos_history.pop(0)perclos=np.mean(self.perclos_history)ifself.perclos_historyelse0# 计算疲劳分数self.fatigue_score=0ifis_eye_closed:self.fatigue_score+=30ifis_yawn:self.fatigue_score+=20ifperclos>self.perclos_threshold:self.fatigue_score+=40# 限制分数范围self.fatigue_score=min(100,self.fatigue_score)return{"ear":ear,"mar":mar,"perclos":perclos,"fatigue_score":self.fatigue_score,"is_eye_closed":is_eye_closed,"is_yawn":is_yawn}

2. Flask后端主程序app.py

fromflaskimportFlask,render_template,request,jsonify,Responseimportcv2importjsonimporttimefromfatigue_detectorimportFatigueDetectorfromyolo_detectorimportBehaviorDetector app=Flask(__name__)detector=FatigueDetector()behavior_detector=BehaviorDetector()@app.route('/')defindex():returnrender_template('index.html')@app.route('/settings')defsettings():returnrender_template('settings.html')@app.route('/update_settings',methods=['POST'])defupdate_settings():data=request.json detector.ear_threshold=data.get('ear_threshold',0.21)detector.mar_threshold=data.get('mar_threshold',0.60)detector.blink_frames=data.get('blink_frames',5)detector.yawn_frames=data.get('yawn_frames',5)detector.perclos_threshold=data.get('perclos_threshold',0.35)returnjsonify({"status":"success"})defgenerate_video_frames(video_path):cap=cv2.VideoCapture(video_path)whilecap.isOpened():ret,frame=cap.read()ifnotret:break# 疲劳检测fatigue_data=detector.detect(frame)# 危险行为检测behavior_data=behavior_detector.detect(frame)# 绘制结果cv2.putText(frame,f"EAR:{fatigue_data['ear']:.3f}",(10,30),cv2.FONT_HERSHEY_SIMPLEX,1,(0,255,0),2)cv2.putText(frame,f"MAR:{fatigue_data['mar']:.3f}",(10,70),cv2.FONT_HERSHEY_SIMPLEX,1,(0,255,0),2)cv2.putText(frame,f"Fatigue Score:{fatigue_data['fatigue_score']}",(10,110),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,255),2)# 转码为JPEG流ret,buffer=cv2.imencode('.jpg',frame)frame_bytes=buffer.tobytes()yield(b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n'+frame_bytes+b'\r\n')@app.route('/video_feed')defvideo_feed():video_path=request.args.get('path',0)returnResponse(generate_video_frames(video_path),mimetype='multipart/x-mixed-replace; boundary=frame')if__name__=='__main__':app.run(host='0.0.0.0',port=5000,debug=True)

3. YOLOv8危险行为检测yolo_detector.py

fromultralyticsimportYOLOimportcv2classBehaviorDetector:def__init__(self,model_path="models/yolov8-behavior.pt",conf=0.5):self.model=YOLO(model_path)self.conf=conf self.classes=["smoking","phone","drinking"]# 抽烟、打电话、喝水defdetect(self,frame):results=self.model(frame,conf=self.conf)behaviors=[]forboxinresults[0].boxes:cls_id=int(box.cls)behaviors.append(self.classes[cls_id])returnbehaviors

五、系统运行步骤

  1. 环境准备:创建虚拟环境并安装依赖,下载dlib模型和YOLOv8权重
  2. 启动服务:运行app.py,访问http://localhost:5000打开主页面
  3. 选择输入源
    • 视频文件:点击「浏览」选择本地视频,点击「开始检测」
    • 摄像头:选择「实时摄像头」,点击「开始检测」
  4. 参数配置:进入「设置」页面,调整YOLO置信度、EAR/MAR阈值、PERCLOS时间窗口等参数
  5. 查看结果:实时显示疲劳分数、EAR、PERCLOS等指标,疲劳时触发预警提示
  6. 报告生成:检测结束后,可导出PDF/Excel格式的疲劳分析报告

六、项目亮点

✅ 多维度疲劳评估:EAR、MAR、PERCLOS、眨眼频率、点头角度多指标综合分析
✅ 双检测模式:支持摄像头实时监测和预录制视频分析
✅ 灵活参数配置:可自定义检测阈值、时间窗口等参数,适配不同场景
✅ 数据可视化:实时显示疲劳指标、历史趋势和预警提示
✅ 报告生成:支持导出PDF/Excel格式的检测报告,方便复盘分析
✅ 模块化设计:核心逻辑与界面分离,便于扩展二次开发


http://www.jsqmd.com/news/919689/

相关文章:

  • 开源阅读鸿蒙版:你的数字阅读管家,打造无广告、全定制的阅读自由
  • Claude Code 桌面端 vs CLI 全面安装指南与对比:2026 最新版,选哪个?
  • 2026年5月更新:温州批发甲醇批发厂家实力盘点,瑞安市汇源贸易有限公司值得信赖 - 2026年企业资讯
  • 当kNN遇上隐私计算:用Python复现2009年那篇经典Secure kNN论文的核心算法
  • 如何快速掌握QKeyMapper:Windows设备互通完全指南
  • 斗提机品牌哪家好?锐禹环保设备值得推荐 - myqiye
  • 【深度解析】Hermes Agent Velocity Release:长期记忆、自进化技能与多智能体任务编排实践
  • NX二次开发避坑指南:为什么你的多线程调用UF函数会崩溃?附安全调用libpart.dll的实战解析
  • 从Palantir到开源方案:手把手教你用Python+Neo4j搭建简易时空知识图谱(避坑指南)
  • 别再死磕LSTM了!用Python手搓一个回声状态网络(ESN),轻松搞定时间序列预测
  • 基于 YOLOv8 的快递纸箱缺陷检测系统(完整项目|可直接运行)快递纸箱缺陷检测数据集训练及应用
  • 2026年四川工业阀门厂家TOP5采购参考推荐 - 优质品牌商家
  • 水上乐园涂料铺什么好?耐磨、附着力和长期浸水稳定性是关键
  • Prometheus监控服务部署与实战指南
  • 【深度解析】Claude Opus 编码模型的工程化使用:长上下文、Agent 工作流与代码审查实战
  • 2026年北京赤火时代水淬炉改造哪家好? - myqiye
  • 运维工程师必备:用PowerShell脚本批量采集局域网内多台Windows电脑的硬件信息
  • 破解网盘限速:智能下载助手让文件传输重回自由时代
  • 如何彻底验证CPU稳定性:CoreCycler硬件测试完整指南
  • 《咫尺华胥》
  • 2026工业离心泵选型推荐:消防泵厂家/深井泵厂家/特殊不锈钢管厂家/球阀厂家/靠谱厂家核心判定维度 - 优质品牌商家
  • 保姆级避坑指南:在Ubuntu 20.04 ROS Noetic上搞定A-LOAM跑KITTI数据集(含源码修改与Ceres 1.14安装)
  • 麦克维尔中央空调新兴代理商靠谱吗?口碑怎么样? - mypinpai
  • 68.专治系统崩溃黑砖!EDL紧急救砖+DFU固件恢复完整可复现方案
  • C++ io_uring的使用小结
  • PlantUML——定时图
  • 音乐格式解密终极指南:5分钟快速解锁加密音频文件的完整免费方案
  • MKS Monster8 3D打印机主板:8轴控制的终极解决方案
  • 2026 南京苏易防水修缮|卫生间、阳台、屋顶、地下室免砸砖漏水专项维修 - 吉修匠
  • DePIN深度解析:从架构原理到实战部署的完整指南