大家好,在这个博客中,我们将构建一个嗜睡检测应用程序,它将检测视频中的人是否变得昏昏欲睡。
这是一个非常有趣且简单的项目,代码甚至不到 80 行,让我们开始吧
看看最终输出
注意——你不会在这里听到警报声,因为它是 GIF,你可以在博客上查看视频:
https://machinelearningprojects.net/drowsiness-detection/
嗜睡检测代码
from imutils import face_utils
import dlib
import cv2
from pygame import mixer
thres = 6
mixer.init()
sound = mixer.Sound('alarm.wav')
dlist = []
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
cap = cv2.VideoCapture(0)
def dist(a,b):
x1,y1 = a
x2,y2 = b
return ((x1-x2)**2 + (y1-y2)**2)**0.5
while True:
# Getting out image by webcam
_, image = cap.read()
# Converting the image to gray scale
gr