broootech/drowseguard
π‘οΈ DrowseGuard - Driver Drowsiness Detection
<div align="center">
Real-time driver fatigue monitoring system using computer vision
  
π₯ Live Demo | π Documentation | π Deploy Your Own
</div>
π― About
DrowseGuard is an intelligent driver drowsiness detection system that monitors eye movements in real-time to detect fatigue and prevent accidents. Using advanced computer vision and the Eye Aspect Ratio (EAR) algorithm, it provides instant alerts when drowsiness is detected.
β¨ Key Features
- π₯ Real-time Detection - WebRTC-based browser video processing
- ποΈ Eye Aspect Ratio (EAR) - Scientifically validated drowsiness metric
- π Multi-modal Alerts - Visual overlays + audio warnings
- βοΈ Configurable Sensitivity - Adjustable thresholds for personalized detection
- π Live Dashboard - Monitor EAR values, alerts, and session time
- π¨ Modern UI - Clean, dark-themed interface
- π Browser-based - No installation required, works in any modern browser
π Quick Start
Using This Space
- Click START in the video feed section
- Grant webcam permission when prompted by your browser
- Position your face in front of the camera
- The system will automatically:
- Detect your face and eyes
- Draw green contours around eyes
- Monitor your Eye Aspect Ratio (EAR)
- Alert you if drowsiness is detected (π€ + sound)
βοΈ Configuration
Adjust detection sensitivity using the sliders in the Configuration panel:
Tips:
- Increase sensitivity (lower EAR) for earlier warnings
- Decrease sensitivity (higher EAR) to reduce false positives
- Reduce frames for faster alerts (but more false alarms)
π§ How It Works
Eye Aspect Ratio (EAR) Algorithm
The system calculates the Eye Aspect Ratio using facial landmarks:
EAR = (||p2 - p6|| + ||p3 - p5||) / (2 * ||p1 - p4||)Where p1-p6 are the 6 facial landmark points for each eye.
Detection Pipeline
- Face Detection β dlib's HOG-based frontal face detector
- Landmark Extraction β 68-point facial landmark predictor
- EAR Calculation β Compute eye openness for both eyes
- Threshold Check β Compare against configurable threshold (default: 0.25)
- Alert Trigger β If EAR < threshold for 20+ consecutive frames
- Multi-modal Alert β Visual overlay + audio warning
Why EAR? When eyes close, the vertical eye distance decreases while horizontal distance remains constant, causing EAR to drop significantly (~40% reduction).
π Dashboard Metrics
Status Indicator
- ποΈ ACTIVE - System monitoring (green)
- π€ DROWSINESS! - Alert triggered (red)
- π· STANDBY - Camera not active (gray)
Real-time Metrics
- Eye Aspect Ratio - Current EAR value (cyan)
- Total Alerts - Cumulative alert count
- Session Time - Elapsed monitoring time (HH:MM:SS)
π οΈ Technical Stack
β οΈ Important Notes
Browser Compatibility
- β Chrome/Edge (recommended)
- β Firefox
- β οΈ Safari (may have WebRTC issues)
- β Internet Explorer (not supported)
Privacy & Security
- β All video processing happens locally in your browser
- β No video data is sent to servers or stored
- β No data collection or analytics
- β Webcam access controlled by browser permissions
Legal Disclaimer
β οΈ This is a demonstration tool for educational purposes. It should NOT be used as the sole safety mechanism in vehicles. Always prioritize adequate rest and avoid driving when fatigued. This tool does not replace professional medical advice or vehicle safety systems.
π Use Cases
- π Long-distance Truckers - Monitor fatigue during extended drives
- π Daily Commuters - Safety during routine travel
- π’ Fleet Management - Monitor commercial drivers
- π¬ Research - Study drowsiness patterns and interventions
- π Education - Learn computer vision and real-time ML
π Local Development
Prerequisites
- Python 3.8+
- Webcam
- Modern browser
Installation
# Clone repository
git clone https://huggingface.co/spaces/YOUR_USERNAME/drowseguard
cd drowseguard
# Install dependencies
pip install -r requirements.txt
# Download dlib model (if not included)
# Place shape_predictor_68_face_landmarks.dat in models/
# Run application
streamlit run main.pyFile Structure
drowseguard/
βββ main.py # Main application
βββ requirements.txt # Dependencies
βββ README.md # This file
βββ assets/
β βββ style.css # Custom UI styling
β βββ *.jpg/png # Sample images
βββ models/
β βββ shape_predictor_68_face_landmarks.dat # Facial landmark model
βββ music.wav # Alert soundπ€ Contributing
Contributions welcome! Areas for improvement:
- [ ] Multi-metric detection (yawn, head pose, blink rate)
- [ ] Mobile responsive layout
- [ ] Alert history logging and analytics
- [ ] Calibration phase for personalized thresholds
- [ ] Multiple language support
- [ ] Offline mode support
π References
- EAR Algorithm: SoukupovΓ‘, T., & Δech, J. (2016). Real-Time Eye Blink Detection using Facial Landmarks.
- dlib Library: http://dlib.net/
- Streamlit-WebRTC: https://github.com/whitphx/streamlit-webrtc
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- dlib for facial landmark detection
- Streamlit for the amazing web framework
- streamlit-webrtc for browser video streaming
- Computer vision research community
<div align="center">
β If you find this useful, please star the Space! β
Made with β€οΈ using Streamlit
π Report Bug | π‘ Request Feature
</div>
