It is a university project focused on making detections whether the driver is drowsy based on the camera output. There has been done two approaches towards this problem - the conventional one and one using machine learning.
Project done fully in Python 3.9 except for two functions made in MATLAB.
Using MediaPipe solutions program gets face and pose landmarks of a user. Particular landmarks' coordinates are used to calculate distances and ratios. Detections are made based on those ratios and thresholds set by the user or via thresholds.txt file.
python Conv/main.pyin the right directory.
In case of lacking packages remember to install the following:
pip install opencv-python
pip install mediapipe
pip install numpy
pip install imutilsIf you want to run a video file instead of capturing webcam type video file directory in "..." in main.py:
if __name__ == '__main__':
video_dir = "..."
main(video_dir)• 1 - drawing the FaceMesh grid
• 2 - drawing the functionality for detecting eye closure
• 3 - drawing the functionality for determining gaze direction
• 4 - drawing the functionality for detecting mouth closure
• 5 - drawing the functionality for determining face direction
• 6 - drawing the Pose grid
• 7 - drawing the functionality for measuring the distance between hands and head
• Backspace - removing all drawn indicators
• C - configuring the detection thresholds for individual states
• S - saving the set thresholds to a text file
• For indicators that use more than one threshold:
•U - setting the upper threshold
•D - setting the lower threshold
•L - setting the left threshold
•R - setting the right threshold
In this case face landmarks obtained with MediaPipe solutions are used to create dataset which is then used to train an AI model. Model is then used to make detections in terms of drowsiness.
python ML/main.pyin the right directory.
In case of lacking packages remember to install the following:
pip install opencv-python
pip install imutils
pip install mediapipe
pip install numpy
pip install pandasIf you want to run a video file instead of capturing webcam type video file directory in "..." in main.py:
if __name__ == '__main__':
models = ["model1", "model2", "model3", ...]
video_dir = "..."
main(video_dir, models[0])python exporting.py
python training.pyAdditionally, remember to change CLASS_NAME according to your data.
Optionally you can run
python data_augmentation.pyin the first place to expand your dataset.
Used datasets:
• dataset 1.
• dataset 2.
• dataset 3. - Research paper