A production-grade driver monitoring solution engineered to prevent accidents caused by drowsiness, fatigue, and distraction. This system leverages computer vision and real-time biometric analysis to continuously assess driver state and trigger multi-modal alerts (Audio, Visual, Email) in critical situations.
Unlike basic prototypes, DSAS features a robust modular architecture, gesture-based SOS system, and a professional analytics dashboard, making it suitable for fleet management integration and advanced safety applications.
- PERCLOS Analysis: Monitors percentage of eye closure over time using EAR (Eye Aspect Ratio).
- Micro-Sleep Detection: Identifies brief, involuntary sleep episodes (0.5s - 2s).
- Yawn Frequency: Tracks mouth opening duration (MAR) to detect early signs of fatigue.
- Head Pose Estimation: Calculates 3D yaw, pitch, and roll to detect when the driver looks away from the road.
- Distraction Alerts: Triggers immediate warnings for sustained inattention (>2s).
- Gesture Recognition: Detects a specific "Hollow Namaste" hand gesture held for 5 seconds.
- Automated Dispatch: Instantly sends an SMTP Email Alert to emergency contacts.
- Rich Metadata: Includes GPS coordinates, timestamp, Google Maps link, and driver details.
- Spam Prevention: Built-in 5-minute cooldown to prevent duplicate emergency broadcasts.
- Visual Feedback: Live graphs for EAR (Eye Aspect Ratio) and Fatigue Scores.
- Session Metrics: Tracks blink rate, microsleep events, and attention lapses.
- Dynamic UI: Modern, dark-themed interface designed for low-light vehicle environments.
The project follows a Service-Oriented Architecture (SOA) pattern, ensuring separation of concerns and scalability.
Driver_Safety_Dashboard/
├── core/ # 🧠 Intelligent Processing Units
│ ├── face_monitor.py # Facial Landmarks & State Machine (EAR/MAR/Pose)
│ ├── hand_gesture.py # Hand Tracking & SOS Logic (MediaPipe)
│ ├── alert_manager.py # Priority Queueing & Alert Orchestration
│ └── analytics_engine.py# Statistical Analysis & Scoring Algorithms
│
├── services/ # 🔌 External Integrations
│ ├── email_service.py # SMTP Client (Gmail/Outlook) with HTML Templates
│ ├── audio_service.py # Multi-threaded Audio/TTS Engine
│ └── location_service.py# IP-based Geolocation & Fallback Logic
│
├── ui/ # 🎨 Visualization Layer
│ ├── dashboard.py # Analytics Rendering Engine
│ ├── display.py # Main Video Compositor & Overlay Manager
│ └── themes.py # Centralized Design System (Colors/Fonts)
│
├── config/ # ⚙️ Configuration Management
│ ├── settings.json # System Thresholds & API Keys
│ └── contacts.json # Emergency Contact Database
│
└── assets/ # 📦 Static Resources
├── models/ # Quantized TFLite Models (Face/Hand)
└── sounds/ # High-fidelity WAV Alerts
- Multi-Factor Fatigue Score: Calculates a 0-100% fatigue index based on blink rate, long blinks, and yawn frequency.
- Adaptive Thresholds: Configurable sensitivity settings in
settings.jsonfor different driver profiles. - Thread-Safe Audio: Non-blocking audio playback using
pygameandthreadingfor zero-latency alerts.
- SMTP Email Client: Robust email dispatcher with TLS security and error handling.
- Geolocation Fallback: Automatic failover logic for location services.
- Text-to-Speech (TTS): Dynamic voice synthesis for spoken warnings ("Please keep your eyes on the road").
- High-FPS Rendering: Optimized
cv2drawing routines for smooth 30+ FPS performance. - Visual Debugging: Skeleton tracking overlay for hands and face mesh verification.
- Dark Mode: Reduces screen glare for night driving safety.
- Python 3.10+
- Webcam (Built-in or USB)
git clone https://github.com/DepthStrider-x/Driver-Safety-Monitor.git
cd Driver_Safety_Dashboard
pip install -r requirements.txt- Open
config/settings.json. - Update the
emailsection with your SMTP credentials (e.g., Gmail App Password)."email": { "smtp_server": "smtp.gmail.com", "sender_email": "your_email@gmail.com", "sender_password": "your_app_password" }
Edit config/contacts.json to define who receives SOS alerts:
"emergency_contacts": [
{
"name": "Family Member",
"email": "receiver@example.com",
"relation": "Spouse"
}
]python main.pyThe system is highly customizable via config/settings.json:
| Parameter | Default | Description |
|---|---|---|
sleep_time |
2.0 |
Seconds of eye closure to trigger DROWSINESS alert. |
yawn_time |
3.0 |
Seconds of mouth open to trigger YAWN alert. |
inattention_time |
2.0 |
Seconds of looking away to trigger FOCUS alert. |
sos_hold_time |
5.0 |
Seconds to hold "Namaste" gesture for SOS. |
sos_cooldown |
300.0 |
Seconds to wait before allowing another SOS trigger. |
- Mobile Integration: Companion Android/iOS app for push notifications.
- Cloud Sync: Upload session logs to AWS/Firebase for fleet analytics.
- IR Camera Support: Enhanced night vision using infrared sensors.
- Heart Rate Monitoring: Integration with rPPG (Remote Photoplethysmography) for vital sign tracking.
This project demonstrates production-ready code quality, including:
- Strict type hinting and modular design.
- Comprehensive error handling and logging.
- Scalable service-oriented architecture.
Pull requests are welcome. For major changes, please open an issue first to discuss the proposed change.
Developed by Aryan Prajapati