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

https://github.com/tigo-cmd/vigilant-eye-cam

๐Ÿ›Œ Vigilant Eye Cam โ€“ Real-Time Drowsiness Detection
https://github.com/tigo-cmd/vigilant-eye-cam

Last synced: 12 months ago
JSON representation

๐Ÿ›Œ Vigilant Eye Cam โ€“ Real-Time Drowsiness Detection

Awesome Lists containing this project

README

          

# ๐Ÿ›Œ Vigilant Eye Cam โ€“ Real-Time Drowsiness Detection

**Vigilant Eye Cam** is a real-time drowsiness detection system built with **React (TypeScript)** on the frontend and a **Flask (Python)** backend. It uses a webcam to monitor a user's face and detect signs of drowsiness using a pre-trained deep learning model. If drowsiness is detected, an alarm is triggered, and a visual warning is displayed.

---

## ๐Ÿš€ Features

* ๐ŸŽฅ **Live Webcam Feed** โ€“ Automatically detects and streams the user's webcam.
* ๐Ÿง  **ML-Based Drowsiness Detection** โ€“ Sends frames to a Flask backend with a TensorFlow model for analysis.
* ๐Ÿ”” **Real-Time Alert System** โ€“ Shows warning banners and plays an alarm if drowsiness is detected.
* ๐Ÿงช **Retry Logic** โ€“ Automatically retries failed detection requests.
* ๐Ÿ–ฅ๏ธ **Mobile-Responsive UI** โ€“ Built with Tailwind CSS and React components.
* ๐Ÿ”‡ **Toggleable Alarm** โ€“ Easily enable or disable the alarm sound.

---

## ๐Ÿ“ Project Structure

```
vigilant-eye-cam/
โ”‚
โ”œโ”€โ”€ frontend/ # React + TypeScript app
โ”‚ โ””โ”€โ”€ src/
โ”‚ โ””โ”€โ”€ components/
โ”‚ โ””โ”€โ”€ DrowsinessDetector.tsx
โ”‚
โ”œโ”€โ”€ backend/ # Flask backend
โ”‚ โ”œโ”€โ”€ app.py
โ”‚ โ””โ”€โ”€ drowsiness_model.h5
โ”‚
โ”œโ”€โ”€ public/
โ”œโ”€โ”€ README.md
```

---

## ๐Ÿง  How It Works

1. The frontend captures a frame every second from the webcam.
2. Each frame is sent as a JPEG image to the Flask backend.
3. The backend loads a pre-trained Keras model (`drowsiness_model.h5`) to analyze the image.
4. The backend responds with:

```json
{ "drowsy": true, "confidence": 0.92 }
```
5. If `drowsy` is `true`, the UI shows a warning banner and triggers an alarm.

---

## ๐Ÿ”ง Setup Instructions

### 1. Backend (Python + Flask)

#### ๐Ÿ“ฆ Requirements

* Python 3.7+
* TensorFlow
* Flask
* OpenCV
* NumPy

#### ๐Ÿ›  Install Dependencies

```bash
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
```

**Sample `requirements.txt`:**

```txt
Flask
tensorflow
opencv-python
numpy
flask-cors
```

#### ๐Ÿง  Start the Backend Server

```bash
python app.py
```

> Ensure `drowsiness_model.h5` exists in the backend folder.

---

### 2. Frontend (React + Vite + Tailwind)

#### ๐Ÿ“ฆ Requirements

* Node.js 18+
* npm or yarn

#### ๐Ÿ›  Install and Start

```bash
cd frontend
npm install
npm run dev
```

> The frontend runs on `http://localhost:5173` and expects the backend at `http://localhost:5000`.

---

## ๐Ÿ“ฑ API Endpoint

### POST `/detect`

* **Headers**: `Content-Type: image/jpeg`
* **Body**: JPEG image blob
* **Response**:

```json
{
"drowsy": true,
"confidence": 0.87
}
```

---

## โš™๏ธ Configuration

| Variable | Default | Description |
| ------------------ | --------- | ---------------------------------- |
| `CAPTURE_INTERVAL` | 1000 ms | Time interval for capturing frames |
| `CAPTURE_WIDTH` | 320 px | Width of the video capture |
| `CAPTURE_HEIGHT` | 240 px | Height of the video capture |
| `BACKEND_URL` | `/detect` | Flask API URL |

---

## ๐Ÿงช Testing

1. Start the backend (`localhost:5000`)
2. Start the frontend (`localhost:5173`)
3. Grant camera permissions
4. Click "Start"
5. Test by:

* Closing your eyes
* Leaning your head
* Looking drowsy

---

## ๐Ÿšฏ Alarm Control

* Toggle alarm ON/OFF using the "Alarm" button
* Dismiss warning using the "Dismiss" button
* Alarm auto-stops when alertness is regained

---

## ๐Ÿง  Model Note

* The `drowsiness_model.h5` must be trained on eye state or facial expression data.
* Image input size and normalization must match training preprocessing.

---

## ๐Ÿ“ธ Screenshots

> *(Add screenshots of the working app with warning banner and camera feed)*

---

## ๐Ÿ›ก๏ธ Security & Privacy

* No frames are stored or shared.
* All processing happens in real-time on the user's device and private backend.

---

## ๐Ÿค Credits

* UI: Tailwind CSS, ShadCN
* Icons: Lucide React
* ML: TensorFlow
* Backend: Flask + OpenCV

---

## ๐Ÿ“„ License

MIT License. Feel free to fork and customize for your own use.