An open API service indexing awesome lists of open source software.

https://github.com/byigitt/no-sleep

Real-time drowsiness detection system using webcam eye tracking. Monitors Eye Aspect Ratio (EAR) via MediaPipe and triggers an alarm when eyes stay closed for too long.
https://github.com/byigitt/no-sleep

computer-vision driver-safety drowsiness-detection eye-tracking face-detection mediapipe opencv python safety webcam

Last synced: 3 months ago
JSON representation

Real-time drowsiness detection system using webcam eye tracking. Monitors Eye Aspect Ratio (EAR) via MediaPipe and triggers an alarm when eyes stay closed for too long.

Awesome Lists containing this project

README

          

# No Sleep

Drowsiness detection system that monitors your eyes via webcam and triggers an alarm if you fall asleep.

## How It Works

1. Captures video from your webcam
2. Uses MediaPipe Face Landmarker to detect 478 facial landmarks
3. Calculates Eye Aspect Ratio (EAR) from 6 points per eye
4. When EAR drops below threshold (eyes closed) for >2 seconds, alarm beeps repeatedly
5. Alarm stops when you open your eyes

## Requirements

- Python 3.10+
- Webcam
- Windows (uses `winsound` for alarm)

## Installation

```bash
uv sync
```

The face landmarker model (~4MB) downloads automatically on first run.

## Usage

```bash
uv run main.py
```

Press `q` to quit.

## Status Indicators

| Color | Status | Meaning |
|-------|--------|---------|
| Green | Awake | Eyes open, all good |
| Orange | Eyes Closed (Xs) | Eyes closing, timer counting |
| Red | DROWSY! | Eyes closed >2s, alarm active |
| Gray | No Face Detected | Camera can't see your face |

## Configuration

Edit these values at the top of `main.py`:

| Variable | Default | Description |
|----------|---------|-------------|
| `EAR_THRESHOLD` | 0.2 | Eye aspect ratio threshold. Lower = more sensitive |
| `CLOSED_DURATION_THRESHOLD` | 2.0 | Seconds before alarm triggers |
| `ALARM_FREQUENCY` | 2500 | Beep frequency in Hz |
| `ALARM_DURATION` | 500 | Beep duration in ms |

## How EAR Works

Eye Aspect Ratio measures how "open" your eyes are:

```
EAR = (|p2-p6| + |p3-p5|) / (2 * |p1-p4|)

p2 p3
p1 p4
p6 p5
```

- Eyes open: EAR ≈ 0.25-0.35
- Eyes closed: EAR < 0.2