|
1 | | -# Drowsiness-Detection-with-OpenCV |
2 | | -Drowsiness detection is a technology that is used to prevent riders from falling asleep during driving. This technology brings protection to riders and co-passengers. By using an IR Camera in Infront of the driver, the algorithm can monitor the area enclosed between the eyes of the driver. When the area falls under curtain measurement for several consecutive frames then the system triggers an alarm to warn the driver to take control of the vehicle. When the driver opens back their eyes and the area goes above the safe region the alarm stops. Thus, this could stop the driver from dozing and save lives. |
| 1 | +# 🚗💤 Drowsiness Detection with OpenCV |
3 | 2 |
|
4 | | -Publication: https://ieeexplore.ieee.org/document/9532758 |
| 3 | +> **Real-time driver drowsiness detection** using computer vision and the Eye Aspect Ratio (EAR) algorithm. |
| 4 | +
|
| 5 | +<p align="center"> |
| 6 | + <a href="https://ieeexplore.ieee.org/document/9532758"><img src="https://img.shields.io/badge/IEEE-Published%20Paper-00629B?style=for-the-badge&logo=ieee&logoColor=white" alt="IEEE Paper"></a> |
| 7 | +</p> |
| 8 | + |
| 9 | +<p align="center"> |
| 10 | + <img src="https://img.shields.io/badge/Python-3.7+-3776AB?style=flat-square&logo=python&logoColor=white"> |
| 11 | + <img src="https://img.shields.io/badge/OpenCV-4.x-5C3EE8?style=flat-square&logo=opencv&logoColor=white"> |
| 12 | + <img src="https://img.shields.io/badge/dlib-face__recognition-green?style=flat-square"> |
| 13 | + <img src="https://img.shields.io/badge/SciPy-EAR%20Computation-8CAAE6?style=flat-square&logo=scipy&logoColor=white"> |
| 14 | + <img src="https://img.shields.io/badge/License-MIT-yellow?style=flat-square"> |
| 15 | +</p> |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## 📄 Publication |
| 20 | + |
| 21 | +This project is published in **IEEE Xplore**: |
| 22 | + |
| 23 | +> **S. Santhanam et al.**, "Real-Time Drowsiness Detection using Computer Vision," *2021 5th International Conference on Computing Methodologies and Communication (ICCMC)*, 2021. |
| 24 | +> |
| 25 | +> 🔗 **[Read the paper on IEEE Xplore →](https://ieeexplore.ieee.org/document/9532758)** |
| 26 | +
|
| 27 | +--- |
| 28 | + |
| 29 | +## 🧠 How It Works |
| 30 | + |
| 31 | +The system uses the **Eye Aspect Ratio (EAR)** to detect drowsiness in real-time: |
| 32 | + |
| 33 | +``` |
| 34 | +EAR = (||p2 - p6|| + ||p3 - p5||) / (2 × ||p1 - p4||) |
| 35 | +``` |
| 36 | + |
| 37 | +``` |
| 38 | + p2 p3 |
| 39 | + •--------• |
| 40 | + / \ |
| 41 | +p1 • • p4 ← horizontal axis |
| 42 | + \ / |
| 43 | + •--------• |
| 44 | + p6 p5 |
| 45 | +``` |
| 46 | + |
| 47 | +- **Eyes open** → EAR ≈ 0.3 |
| 48 | +- **Eyes closed** → EAR ≈ 0.05 |
| 49 | +- If EAR stays below a threshold for enough consecutive frames → **🚨 ALARM** |
| 50 | + |
| 51 | +### Architecture |
| 52 | + |
| 53 | +``` |
| 54 | +┌──────────┐ ┌──────────────┐ ┌───────────┐ ┌───────────┐ |
| 55 | +│ Webcam │───▶│ Face Landmark │───▶│ Compute │───▶│ Trigger │ |
| 56 | +│ Stream │ │ Detection │ │ EAR │ │ Alarm? │ |
| 57 | +└──────────┘ └──────────────┘ └───────────┘ └───────────┘ |
| 58 | + face_recognition scipy playsound |
| 59 | +``` |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## ✨ Features |
| 64 | + |
| 65 | +- 🎥 Real-time webcam-based detection |
| 66 | +- 👁️ Eye Aspect Ratio (EAR) algorithm |
| 67 | +- 🔊 Audio alarm on drowsiness detection |
| 68 | +- 📊 Live EAR display overlay |
| 69 | +- ⚙️ Configurable thresholds via CLI args |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +## 🚀 Getting Started |
| 74 | + |
| 75 | +### Prerequisites |
| 76 | + |
| 77 | +- Python 3.7+ |
| 78 | +- Webcam |
| 79 | +- CMake (for dlib): `brew install cmake` (macOS) or `apt install cmake` (Linux) |
| 80 | + |
| 81 | +### Installation |
| 82 | + |
| 83 | +```bash |
| 84 | +git clone https://github.com/Sanjays2402/Drowsiness-Detection-with-OpenCV.git |
| 85 | +cd Drowsiness-Detection-with-OpenCV |
| 86 | +pip install -r requirements.txt |
| 87 | +``` |
| 88 | + |
| 89 | +### Usage |
| 90 | + |
| 91 | +```bash |
| 92 | +# Default settings |
| 93 | +python drowsiness_detection.py |
| 94 | + |
| 95 | +# Custom thresholds |
| 96 | +python drowsiness_detection.py --ear-threshold 0.22 --frame-count 48 |
| 97 | + |
| 98 | +# Different video source |
| 99 | +python drowsiness_detection.py --video-source 1 |
| 100 | +``` |
| 101 | + |
| 102 | +Press **`q`** to quit. |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +## ⚙️ Configuration |
| 107 | + |
| 108 | +| Parameter | Flag | Default | Description | |
| 109 | +|-----------|------|---------|-------------| |
| 110 | +| EAR Threshold | `--ear-threshold` | `0.25` | EAR below this = eyes closed | |
| 111 | +| Frame Count | `--frame-count` | `60` | Consecutive frames before alarm | |
| 112 | +| Video Source | `--video-source` | `0` | Webcam index | |
| 113 | +| Alarm Sound | `--alarm-sound` | `assets/alert1.mp3` | Path to alert audio | |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +## 🎬 Demo |
| 118 | + |
| 119 | +> *Add a GIF or screenshot here!* |
| 120 | +> |
| 121 | +>  |
| 122 | +
|
| 123 | +--- |
| 124 | + |
| 125 | +## 📁 Project Structure |
| 126 | + |
| 127 | +``` |
| 128 | +├── drowsiness_detection.py # Main detection script |
| 129 | +├── assets/ |
| 130 | +│ └── alert1.mp3 # Alarm sound |
| 131 | +├── requirements.txt |
| 132 | +├── LICENSE |
| 133 | +└── README.md |
| 134 | +``` |
| 135 | + |
| 136 | +--- |
| 137 | + |
| 138 | +## 🛠️ Tech Stack |
| 139 | + |
| 140 | +- **[OpenCV](https://opencv.org/)** — Video capture & frame processing |
| 141 | +- **[face_recognition](https://github.com/ageitgey/face_recognition)** — Facial landmark detection (dlib-based) |
| 142 | +- **[SciPy](https://scipy.org/)** — Euclidean distance for EAR |
| 143 | +- **[imutils](https://github.com/PyImageSearch/imutils)** — Video stream utilities |
| 144 | +- **[playsound](https://github.com/TaylorSMarks/playsound)** — Audio alarm playback |
| 145 | + |
| 146 | +--- |
| 147 | + |
| 148 | +## 📜 License |
| 149 | + |
| 150 | +[MIT](LICENSE) © Sanjay Santhanam |
| 151 | + |
| 152 | +## 👤 Author |
| 153 | + |
| 154 | +**Sanjay Santhanam** — [GitHub](https://github.com/Sanjays2402) |
0 commit comments