Skip to content

DepthStrider-x/Driver-Safety-Monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚗 Driver Safety & Alert System (DSAS)

Python OpenCV MediaPipe Status

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.


📸 System Capabilities

1. Intelligent Drowsiness Detection

  • 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.

2. Attention Monitoring

  • 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).

3. 🆘 SOS Emergency Protocol

  • 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.

4. Real-Time Analytics Dashboard

  • 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.

🏗️ Technical Architecture

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

🚀 Key Features

🛡️ Core Safety Engine

  • 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.json for different driver profiles.
  • Thread-Safe Audio: Non-blocking audio playback using pygame and threading for zero-latency alerts.

📡 Connectivity & Services

  • 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").

📊 Professional UI/UX

  • High-FPS Rendering: Optimized cv2 drawing 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.

🛠️ Installation & Setup

Prerequisites

  • Python 3.10+
  • Webcam (Built-in or USB)

1. Clone & Install

git clone https://github.com/DepthStrider-x/Driver-Safety-Monitor.git
cd Driver_Safety_Dashboard
pip install -r requirements.txt

2. Configure Credentials

  1. Open config/settings.json.
  2. Update the email section 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"
    }

3. Add Emergency Contacts

Edit config/contacts.json to define who receives SOS alerts:

"emergency_contacts": [
    {
        "name": "Family Member",
        "email": "receiver@example.com",
        "relation": "Spouse"
    }
]

4. Run the System

python main.py

⚙️ Configuration Guide

The 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.

🔮 Future Roadmap

  • 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.

🤝 Contributing

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

About

Driver Safety & Alert System (DSAS) is a production-grade, real-time driver monitoring system built with Python, OpenCV, and MediaPipe to detect drowsiness, fatigue, and distraction using biometric and head-pose analysis.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages