Skip to content

Commit dfb8aa1

Browse files
committed
✨ Polish repo: professional README, clean code, add project files
1 parent d76e009 commit dfb8aa1

6 files changed

Lines changed: 362 additions & 86 deletions

File tree

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Byte-compiled / optimized
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
7+
# Distribution / packaging
8+
dist/
9+
build/
10+
*.egg-info/
11+
*.egg
12+
13+
# Virtual environments
14+
venv/
15+
env/
16+
.venv/
17+
18+
# IDE
19+
.vscode/
20+
.idea/
21+
*.swp
22+
*.swo
23+
*~
24+
25+
# OS
26+
.DS_Store
27+
Thumbs.db
28+
29+
# Misc
30+
*.log

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Sanjay Santhanam
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 153 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,154 @@
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
32

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+
> ![Demo placeholder](https://via.placeholder.com/600x300?text=Add+Demo+GIF+Here)
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)
File renamed without changes.

0 commit comments

Comments
 (0)