YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
π Driver Drowsiness Detection using MediaPipe & OpenCV
π Overview
This project detects driver drowsiness using MediaPipe Face Mesh and OpenCV.
It tracks the driverβs eye aspect ratio (EAR) β when the eyes remain closed for too long, the system detects drowsiness.
The output video is processed frame-by-frame, and an alert message is triggered when drowsiness is detected.
The project is implemented in Google Colab and saves the output video directly to Google Drive.
π― Objective
To ensure road safety by detecting if a driver is becoming sleepy or inattentive while driving.
This project can be extended into a real-time in-vehicle monitoring system.
π§ How It Works
- The system captures video input (uploaded by user).
- MediaPipe Face Mesh detects facial landmarks around the eyes.
- The Eye Aspect Ratio (EAR) is calculated using key eye landmark distances.
- If the EAR value stays below a threshold for a certain number of frames, the driver is classified as drowsy.
- The processed video is saved with alert annotations.
βοΈ Features
β
Real-time facial landmark detection with MediaPipe
β
Eye Aspect Ratio (EAR) based drowsiness detection
β
Automatic alert overlay on drowsy frames
β
Saves output video to Google Drive
π§© Requirements
Install dependencies in Google Colab:
!pip install opencv-python mediapipe numpy scipy
Import libraries:
import cv2
import mediapipe as mp
import numpy as np
from scipy.spatial import distance as dist
π Folder Structure
Driver-Monitoring-System-YOLOv8/
β
βββ drowsiness_detection.ipynb # Main Colab Notebook
βββ driver_drowsiness_input.mp4 # Input video (user-provided)
βββ driver_drowsiness_output.mp4 # Output video (saved in Drive)
βββ README.md # Documentation file
π Steps to Run in Colab
Mount your Google Drive:
from google.colab import drive drive.mount('/content/drive')Upload your input video to your Drive folder, e.g.:
/content/drive/MyDrive/AI ML Projects/Driver-Monitoring-System-YOLOv8/driver_drowsiness_input.mp4Run the detection code.
The output video will be automatically saved as:/content/drive/MyDrive/AI ML Projects/Driver-Monitoring-System-YOLOv8/driver_drowsiness_output.mp4
π Results
- Detects and highlights drowsy driver moments.
- Annotates the video with alerts (βDrowsiness Detectedβ).
- Saves the processed video automatically to Google Drive.
π§© Formula Used β Eye Aspect Ratio (EAR)
The EAR is calculated using the Euclidean distance between eye landmarks:
( EAR = rac{||p2 - p6|| + ||p3 - p5||}{2 * ||p1 - p4||} )
If EAR < 0.25 for several frames, drowsiness is detected.
π§ Future Directions
πΉ Combine with YOLOv8 for mobile phone + drowsiness multi-detection.
πΉ Add audio alerts for real-time feedback.
πΉ Integrate into a desktop or mobile app for driver safety monitoring.
πΉ Train a model to detect yawning and head tilt as additional drowsiness signs.
π§βπ» Author
Fatima Noor
π AI/ML Developer | Python Enthusiast
π GitHub Repository)
π Conclusion
This project demonstrates how computer vision can be applied for driver safety monitoring using AI-powered eye-tracking.
Itβs a great base project for building an intelligent in-vehicle alert system.