CoolFace
Apppublic

broootech/drowseguard

sourceHugging Facemitupdated 8mo agoView on Hugging Face
0likes
App README

πŸ›‘οΈ DrowseGuard - Driver Drowsiness Detection

<div align="center">

Real-time driver fatigue monitoring system using computer vision

![Streamlit](https://streamlit.io) ![Python](https://www.python.org) ![License](LICENSE)

πŸŽ₯ 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

  1. 1.Click START in the video feed section
  2. 2.Grant webcam permission when prompted by your browser
  3. 3.Position your face in front of the camera
  4. 4.The system will automatically:
  5. 5.Detect your face and eyes
  6. 6.Draw green contours around eyes
  7. 7.Monitor your Eye Aspect Ratio (EAR)
  8. 8.Alert you if drowsiness is detected (πŸ’€ + sound)

βš™οΈ Configuration

Adjust detection sensitivity using the sliders in the Configuration panel:

SettingRangeDefaultDescription
EAR Sensitivity0.15 - 0.350.25Lower = more sensitive detection
Alert Delay5 - 50 frames20Frames before triggering alert

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

  1. 1.Face Detection β†’ dlib's HOG-based frontal face detector
  2. 2.Landmark Extraction β†’ 68-point facial landmark predictor
  3. 3.EAR Calculation β†’ Compute eye openness for both eyes
  4. 4.Threshold Check β†’ Compare against configurable threshold (default: 0.25)
  5. 5.Alert Trigger β†’ If EAR < threshold for 20+ consecutive frames
  6. 6.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

ComponentTechnology
FrameworkStreamlit 1.36.0
Video Streamingstreamlit-webrtc, WebRTC
Computer VisionOpenCV, dlib
Face Detectiondlib frontal face detector
Landmarks68-point facial landmark predictor
Scientific ComputingNumPy, SciPy

⚠️ 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

bash
# 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.py

File 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


πŸ“„ 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>