Real-time Driver Monitoring System using Python, OpenCV and MediaPipe FaceMesh
- Project Overview
- Features
- Technologies Used
- Project Workflow
- Detection Parameters
- Performance
- Limitations
- Project Structure
- Installation
- Usage
- How It Works
- Libraries
- Roadmap
- Future Improvements
- Contributing
- License
Driver fatigue is one of the leading causes of road accidents worldwide. This project provides a real-time Driver Monitoring System (DMS) that continuously analyzes the driver's facial landmarks using MediaPipe FaceMesh.
The system estimates the driver's alertness using:
- ๐ Eye Aspect Ratio (EAR)
- ๐ฎ Mouth Aspect Ratio (MAR)
- ๐ด Percentage of Eye Closure (PERCLOS)
- ๐ง Head Pose Estimation
If signs of drowsiness persist beyond predefined thresholds, the system automatically detects the driver's fatigue state and can trigger an alert.
- โ Real-time webcam monitoring
- โ Face detection using MediaPipe FaceMesh
- โ 468 facial landmark detection
- โ Eye Aspect Ratio (EAR) calculation
- โ Mouth Aspect Ratio (MAR) calculation
- โ Percentage of Eye Closure (PERCLOS)
- โ Head Pose estimation
- โ Driver state classification
- โ Lightweight and fast
- โ Modular Python implementation
- โ Easy to customize thresholds
- Python
- OpenCV
- MediaPipe FaceMesh
- NumPy
Webcam
โ
โผ
Face Detection
โ
โผ
MediaPipe FaceMesh
(468 Landmarks)
โ
โโโโโโโโโโผโโโโโโโโโ
โผ โผ โผ
EAR MAR Head Pose
โ โ โ
โโโโโโโโโโผโโโโโโโโโ
โผ
Driver State Analysis
โผ
Drowsiness Detection
โผ
Driver Alert
Measures eye openness.
Lower EAR values indicate prolonged eye closure and possible drowsiness.
Measures mouth opening.
Higher MAR values indicate yawning.
Percentage of Eye Closure over time.
PERCLOS is one of the most reliable fatigue indicators used in modern Driver Monitoring Systems.
Tracks the driver's head orientation.
Detects excessive downward or sideways head movement indicating fatigue or distraction.
- Real-time Processing
- Approximately 25โ30 FPS
- Detects 468 facial landmarks
- Low latency
- Lightweight implementation
- Works with one driver at a time
- Requires sufficient lighting
- Performance decreases if the face is heavily occluded
- Requires a webcam
Driving-Monitor-in-Python/
โ
โโโ calibration/
โโโ detection/
โโโ demo/
โ โโโ demo.gif
โโโ images/
โ โโโ banner.png
โ โโโ face_detection.png
โ โโโ landmarks.png
โ โโโ alert.png
โโโ main.py
โโโ state.py
โโโ utils.py
โโโ face_landmarker.task
โโโ requirements.txt
โโโ LICENSE
โโโ README.md
git clone https://github.com/badivana/Driving-Monitor-in-Python.git
cd Driving-Monitor-in-Pythonpip install -r requirements.txtRun the application
python main.pyThe application will:
- Open your webcam
- Detect facial landmarks
- Calculate Eye Aspect Ratio (EAR)
- Calculate Mouth Aspect Ratio (MAR)
- Estimate Head Pose
- Monitor driver fatigue
- Display alerts when drowsiness is detected
Press Esc to exit.
The Driver Monitoring System consists of three major components.
Uses MediaPipe FaceMesh to detect 468 facial landmarks in real time.
Calculates the driver's head orientation using facial landmarks.
Combines:
- Eye Aspect Ratio (EAR)
- Mouth Aspect Ratio (MAR)
- PERCLOS
- Head Pose
to classify the driver as:
๐ข Alert
๐ด Drowsy
- OpenCV
- MediaPipe
- NumPy
- Face Detection
- Eye Aspect Ratio (EAR)
- Mouth Aspect Ratio (MAR)
- Head Pose Estimation
- Driver State Classification
- Drowsiness Detection
- Audio Alarm
- Mobile Notifications
- Raspberry Pi Deployment
- TensorFlow Lite Optimization
- Multi-person Detection
- Streamlit Dashboard
- Audio warning system
- Mobile notification support
- TensorFlow Lite optimization
- Raspberry Pi deployment
- Infrared camera support
- Driver identification
- Performance benchmarking
- Cloud logging
- AI-based fatigue prediction
Contributions are welcome.
If you find a bug or have an improvement, feel free to:
- Fork the repository
- Create a new branch
- Commit your changes
- Open a Pull Request
This project is licensed under the MIT License.
Please consider giving the repository a โญ on GitHub