Fatigue (Drowsiness) Detection using OpenCV (Assignment Sample)

Опубликовано: 13 Ноябрь 2024
на канале: ICT UoM
377
11

By Reeshal Rittoo (CVBPR S1 27)
BSc Computer Science Year 3
University of Mauritius
CSE 3093Y Computer Vision, Biometrics and Pattern Recognition
March 2021
The system uses a webcam in order to analyse the user’s face and then detects whether he is drowsy. It monitors two facial features, the eyes and the mouth of the user. Then the system emits a text to wake up the latter.

Main steps in the program
1. Initialise all thresholds needed.
2. Load the haarcascade_frontal face file in the cascade classifier of opencv. It contains lots of images of faces.
3. Load a face landmarks file in the shape predictor of dlib. It allows us to localise specific parts of the face.
4. Open the webcam and read each frame.
5. Resize each frame.
6. Convert each frame to grayscale as it is less complex and easier to work with grayscale images than color images.
7. Apply a detectMultiScale function to identify the rectangles containing faces.
8. In each rectangle, we calculate the eye aspect ratio of both eyes using the landmark file.
9. We also calculate the distance between the top and bottom lip on the face in order to detect yawns.
10. We then draw the contours of the eyes and mouth on each frame.
11. If the eye aspect ratio of a frame is lower than the threshold for a drowsy eye aspect ratio, we increase a count and check the same for the next frames.
12.If the next consecutive frames have an aspect ratio lower than the threshold, it means the user is drowsy and an alarm is triggered, telling the user to wake up.
13.Similarly, if the distance between the top and bottom lip is greater than the threshold for yawns, the user is alerted through a voice audio again.
14.The two alarms and the thresholds are also displayed on each frame.