MATLAB疲劳检测-闭眼检测
瞌睡经常发生在汽车行驶的过程中,该行为害人害己,如果有一套能识别瞌睡的系统,那么无疑该系统意义重大!
在这里插入图片描述
实现步骤
思路:疲劳驾驶的司机大部分都有打瞌睡的情形,所以我们根据驾驶员眼睛闭合的频率和时间来判断驾驶员是否疲劳驾驶(或嗜睡)。
详细实现步骤
【1】眼部关键点检测。
在这里插入图片描述
我们使用Face Mesh来检测眼部关键点,Face Mesh返回了468个人脸关键点: 由于我们专注于驾驶员睡意检测,在468个点中,我们只需要属于眼睛区域的标志点。眼睛区域有 32 个标志点(每个 16 个点)。为了计算 EAR,我们只需要 12 个点(每只眼睛 6 个点)。
以上图为参考,选取的12个地标点如下:
对于左眼: [362, 385, 387, 263, 373, 380]
对于右眼:[33, 160, 158, 133, 153, 144]
选择的地标点按顺序排列:P 1、 P 2、 P 3、 P 4、 P 5、 P 6
```bash
```bash
import cv2
import numpy as np
import matplotlib.pyplot as plt
import mediapipe as mp
mp_facemesh = mp.solutions.face_meshmp_drawing = mp.solutions.drawing_utilsdenormalize_coordinates = mp_drawing._normalized_to_pixel_coordinates
%matplotlib inline
获取双眼的地标(索引)点。
`
```bash# Landmark points corresponding to left eyeall_left_eye_idxs = list(mp_facemesh.FACEMESH_LEFT_EYE)# flatten and remove duplicatesall_left_eye_idxs = set(np.ravel(all_left_eye_idxs))
# Landmark points corresponding to right eyeall_right_eye_idxs = list(mp_facemesh.FACEMESH_RIGHT_EYE)all_right_eye_idxs = set(np.ravel(all_right_eye_idxs))
# Combined for plotting - Landmark points for both eyeall_idxs = all_left_eye_idxs.union(all_right_eye_idxs)
# The chosen 12 points: P1, P2, P3, P4, P5, P6chosen_left_eye_idxs = [362, 385, 387, 263, 373, 380