A computer vision system based on opencv that monitors a video stream for driver drowsiness and plays an alarm if the driver appears to be sleepy.
Python is the programming language used in the example code (version 2.7 and higher will work).
- import cv2
- import immutils
- import dlib
- import scipy
- import playsound
- import queue
- import time
- import sys
● Based on a modification to the Histogram of Oriented Gradients, we used Linear SVM for classification in combination with a pre-trained frontal face detector from Dlib's library.
● The pre-trained facial landmark detector in the dlib library is used to estimate the position of 68 (x, y)-coordinates that correspond to facial structures on the face. The following figure illustrates the 68 landmark output. We used the 70 landmark model, however.
● The aspect ratio is then calculated to see if the eyes are open or closed.
● If the Eye Aspect Ratio is larger than a threshold, the eye is open. (Roughly 0.3)
● A blink should last between 200 and 300 milliseconds.
● A sleepy blink would last 800-900 milliseconds.
It can be used by riders who tend to drive for longer periods, where drowsines could result in accidents.