Skip to content

A real-time drowsiness detection system using MediaPipe FaceMesh and Eye Aspect Ratio (EAR) to monitor eye closure and detect signs of fatigue through a webcam feed.

Notifications You must be signed in to change notification settings

vatsalm1611/driver-drowsiness-detection-system

Repository files navigation

SafeDrive – Real-Time Drowsiness Detection System

Banner

A real-time driver drowsiness detection system using Mediapipe Face Mesh, OpenCV, and EAR/MAR-based alerting.


🚀 Features

Feature Description
👁️ Real-time Eye Tracking Uses Mediapipe Face Mesh to track eye landmarks frame-by-frame
😴 Drowsiness Detection (EAR) Detects prolonged eye closure using Eye Aspect Ratio
🗣️ Yawn Detection (MAR) Identifies yawning patterns using Mouth Aspect Ratio
🔊 Instant Alerts Triggers audio alarms on detecting drowsiness
🎥 Streamlit Web App Live, browser-based detection using webcam

📸 Demo

(Add gif or images here)

demo.gif

📁 Project Structure

driver-drowsiness-detection-system
│── drowsy_detection.py
│── audio_handling.py
│── streamlit_app.py
│── requirements.txt
│── README.md
│
├── audio/
│   └── wake_up.wav
│
├── test-open-eyes.jpg
└── test-close-eyes.jpg

🛠️ Tech Stack

  • Python
  • OpenCV
  • Mediapipe Face Mesh
  • Streamlit
  • streamlit-webrtc
  • pydub / av

⚙️ Installation

1️⃣ Clone the repository

git clone https://github.com/vatsalm1611/driver-drowsiness-detection-system
cd driver-drowsiness-detection-system

2️⃣ Install dependencies

pip install -r requirements.txt

▶️ Run the System

Option A — Run Streamlit Web App

streamlit run streamlit_app.py

Option B — Run the basic webcam EAR monitor

python drowsy_detection.py

🔍 How It Works

Eye Aspect Ratio (EAR)

  • Detects eye openness using 6 facial landmark points.
  • If EAR < threshold for continuous duration → Drowsiness detected.

Mouth Aspect Ratio (MAR)

  • Detects wide mouth opening (yawn).
  • MAR > threshold → Yawn event.

🎯 Key Logic (Simplified)

Drowsiness = EAR below threshold for X seconds
Yawn = MAR above threshold

Both metrics are computed per frame → real-time detection.


🤝 Contributing

Contributions are welcome!

  1. Fork the repo
  2. Create a new branch
  3. Commit your changes
  4. Open a Pull Request

📝 License

This project is licensed under the MIT License.


🙏 Acknowledgements

  • Mediapipe team
  • OpenCV community
  • Streamlit contributors

If you like this project, ⭐ the repository!

About

A real-time drowsiness detection system using MediaPipe FaceMesh and Eye Aspect Ratio (EAR) to monitor eye closure and detect signs of fatigue through a webcam feed.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published