🎯 A comprehensive real-time driver fatigue detection system with AI-powered monitoring, web dashboard, and alert management
Final Year Project - Computer Engineering
📋 Table of Contents • 🎥 Demo • 🚀 Quick Start • 📖 Documentation • 👥 Authors
- 🎯 Overview
- 🎥 Video Demo
- 👥 Authors
- ✨ Features
- 🏗️ System Architecture
- 🛠️ Technology Stack
- 📁 Project Structure
- 🚀 Installation & Setup
- 💻 Usage
- 📡 API Documentation
- ⚙️ Configuration
- 🚢 Deployment
- 🤝 Contributing
- 📄 License
The Driver Drowsiness Detection System is an intelligent solution designed to monitor driver fatigue in real-time using computer vision and machine learning. The system consists of three main components:
| 🧠 AI Detection Module | 🔧 Backend API | 🎨 Web Dashboard |
|---|---|---|
| Real-time face and eye tracking | RESTful API for data management | Modern React-based frontend |
| OpenCV & MediaPipe | Go & PostgreSQL | TypeScript & Tailwind CSS |
The system continuously analyzes driver behavior, detects signs of drowsiness, and triggers alerts to prevent accidents. It provides comprehensive dashboards for both drivers and administrators to monitor fatigue levels, view historical data, and manage alerts.
Watch our AI system detect driver drowsiness in real-time using facial recognition and eye tracking technology.
📹 Demo Video: AI Face Detection & Drowsiness Monitoring
📺 Video Details
🎥 YouTube Video: Watch on YouTube
This demonstration video showcases:
- ✅ Real-time face detection using Haar Cascade classifier
- ✅ Eye landmark detection with MediaPipe
- ✅ Eye Aspect Ratio (EAR) calculation
- ✅ Drowsiness level classification (Normal → Low → Medium → High)
- ✅ Visual feedback with live video feed
- ✅ Audio alert system activation
- ✅ GUI interface with status indicators
💡 Click the image above or the button to watch the full demo on YouTube!
This project was developed by:
| Mr. Patchara Al-umaree | Mr. Thanapon Dongphuyaw | Mr. Disorn Suppartum |
| Feature | Description |
|---|---|
| 👁️ Real-time Face Detection | Haar Cascade classifier for robust face detection |
| 📊 Eye Aspect Ratio (EAR) Calculation | Precise eye closure detection using facial landmarks |
| 🎯 Drowsiness Level Classification | Multi-level fatigue detection (normal, low, medium, high) |
| 🖥️ Visual Feedback | Real-time GUI with live video feed and status indicators |
| 🔊 Audio Alerts | Automatic alarm system when drowsiness is detected |
| 🔄 Cross-platform Support | Works on Raspberry Pi and Windows systems |
| Feature | Description |
|---|---|
| 🌐 RESTful Architecture | Clean and well-structured API endpoints |
| 🗄️ PostgreSQL Database | Reliable data storage with automatic migrations |
| 🔐 JWT Authentication | Secure user authentication and authorization |
| ⚡ Real-time Data Processing | Efficient handling of device data streams |
| 🚨 Alert Management | Comprehensive alert tracking and acknowledgment system |
| 👨💼 Admin Dashboard Support | Specialized endpoints for administrative functions |
| 🧹 Automatic Data Purge | Daily cleanup of old data to maintain performance |
| Feature | Description |
|---|---|
| 🎨 Modern UI/UX | Beautiful, responsive design built with React and Tailwind CSS |
| 🚗 Driver Dashboard | Personal monitoring interface with real-time statistics |
| 👑 Master Dashboard | Administrative overview with multi-driver analytics |
| 🔑 User Authentication | Secure login and registration system |
| 👤 Profile Management | User profile customization and settings |
| 📈 Data Visualization | Interactive charts and graphs using Recharts |
| 🔄 Real-time Updates | Live data synchronization with backend |
╔═══════════════════════════════════════════════════════════════╗
║ 🚗 Driver Drowsiness Detection System 🚗 ║
╚═══════════════════════════════════════════════════════════════╝
│
┌─────────────────────┼─────────────────────┐
│ │ │
▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ AI Module │ │ Go Backend │ │ React Frontend │
│ (Python) │───▶│ (API) │◀───│ (Dashboard) │
│ │ │ │ │ │
│ • OpenCV │ │ • PostgreSQL │ │ • React 18 │
│ • MediaPipe │ │ • JWT Auth │ │ • TypeScript │
│ • Haar Cascade│ │ • REST API │ │ • Tailwind CSS│
└───────────────┘ └───────────────┘ └───────────────┘
│ │ │
│ │ │
└─────────────────────┴─────────────────────┘
│
▼
┌─────────────────┐
│ PostgreSQL │
│ Database │
└─────────────────┘
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Detection │────▶│ Processing │────▶│Transmission │
│ (Camera) │ │ (EAR Calc) │ │ (REST API) │
└─────────────┘ └─────────────┘ └─────────────┘
│
▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│Visualization│◀────│ Storage │◀────│ Backend │
│ (Frontend) │ │ (PostgreSQL)│ │ (Go API) │
└─────────────┘ └─────────────┘ └─────────────┘
│
▼
┌─────────────┐
│ Alerts │
│ (Audio/UI) │
└─────────────┘
Flow Steps:
- 📹 Detection - AI module captures video feed and analyzes driver's face
- 🧮 Processing - Eye aspect ratio and drowsiness metrics are calculated
- 📡 Transmission - Data is sent to Go backend via REST API
- 💾 Storage - Backend stores data in PostgreSQL database
- 📊 Visualization - React frontend fetches and displays data in real-time
- 🚨 Alerts - System triggers audio/visual alerts when drowsiness is detected
| Technology | Purpose |
|---|---|
| 🐍 Python 3.10+ | Core programming language |
| 📷 OpenCV | Computer vision and image processing |
| 👁️ MediaPipe | Face and landmark detection |
| 🔢 NumPy | Numerical computations |
| 🔬 SciPy | Scientific computing |
| 🖼️ Tkinter | GUI framework |
| 🌐 Requests | HTTP client for API communication |
| Technology | Purpose |
|---|---|
| 🐹 Go 1.21+ | Core programming language |
| 🚀 Gin | Web framework |
| 🗄️ PostgreSQL | Relational database |
| 🔐 JWT | Authentication tokens |
| 📦 lib/pq | PostgreSQL driver |
| Technology | Purpose |
|---|---|
| ⚛️ React 18.3 | UI framework |
| 📘 TypeScript | Type-safe JavaScript |
| ⚡ Vite | Build tool and dev server |
| 🎨 Tailwind CSS | Utility-first CSS framework |
| 🧩 Radix UI | Accessible component library |
| 📈 Recharts | Chart library |
| 📝 React Hook Form | Form management |
| 🎯 Lucide React | Icon library |
Driver-Drowsiness-Detection-System/
│
├── Driver-Fatigue-Detector_Raspberry/ # AI Detection Module
│ ├── core/
│ │ ├── detector.py # Main detection logic
│ │ ├── calculation.py # EAR calculations
│ │ ├── backend_api.py # API client
│ │ ├── notification_handler.py # Alert management
│ │ └── sound.py # Audio alerts
│ ├── gui/
│ │ ├── gui_main.py # Main GUI window
│ │ └── gui_update.py # GUI update logic
│ ├── models/
│ │ └── haarcascade_frontalface_default.xml # Face detection model
│ ├── main.py # Entry point
│ ├── requirements.txt # Python dependencies
│ ├── RUN_raspberry.sh # Raspberry Pi startup script
│ └── RUN_windows.bat # Windows startup script
│
├── go-backend/ # Backend API
│ ├── config/
│ │ └── config.go # Configuration management
│ ├── database/
│ │ └── database.go # Database connection & migrations
│ ├── handlers/
│ │ └── handlers.go # API route handlers
│ ├── models/
│ │ └── models.go # Data models
│ ├── main.go # Entry point
│ ├── go.mod # Go dependencies
│ ├── schema_register.sql # Database schema
│ └── README.md # Backend documentation
│
├── src/ # Frontend Dashboard
│ ├── components/
│ │ ├── AuthContext.tsx # Authentication context
│ │ ├── HomePage.tsx # Landing page
│ │ ├── LoginPage.tsx # Login interface
│ │ ├── SignupPage.tsx # Registration interface
│ │ ├── DriverDashboard.tsx # Driver dashboard
│ │ ├── MasterDashboard.tsx # Admin dashboard
│ │ ├── ProfilePage.tsx # User profile
│ │ └── ui/ # UI components
│ ├── utils/
│ │ ├── auth.ts # Auth utilities
│ │ └── algorithms.ts # Helper algorithms
│ ├── App.tsx # Main app component
│ └── main.tsx # Entry point
│
├── package.json # Frontend dependencies
├── vite.config.ts # Vite configuration
├── tailwind.config.js # Tailwind configuration
└── README.md # This file
| Requirement | Version | Purpose |
|---|---|---|
| 🐍 Python | 3.10+ | AI Detection Module |
| 🐹 Go | 1.21+ | Backend API |
| 📦 Node.js | 18+ | Frontend Dashboard |
| 🗄️ PostgreSQL | 14+ | Database |
| 📷 Camera/Webcam | Any | Detection Input |
cd Driver-Fatigue-Detector_Raspberry
pip install -r requirements.txtcd Driver-Fatigue-Detector_Raspberry
pip3 install -r requirements.txtEdit core/backend_api.py to configure the backend API URL:
BACKEND_URL = "http://localhost:8080" # Change to your backend URL
DEVICE_ID = "device_01" # Unique device identifiercd go-backend
go mod download- Install PostgreSQL from postgresql.org
- Create a new database:
CREATE DATABASE drowsiness_db;Create a .env file in go-backend/ directory:
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your_password
DB_NAME=drowsiness_db
PORT=8080
ENV=development
JWT_SECRET=your-secret-key-hereThe backend will automatically run migrations on first startup.
npm installCreate a .env file in the root directory:
VITE_API_URL=http://localhost:8080npm run devThe frontend will be available at http://localhost:3000
cd go-backend
go run main.go✅ Backend will run on http://localhost:8080
npm run dev✅ Frontend will run on http://localhost:3000
🪟 Windows:
cd Driver-Fatigue-Detector_Raspberry
RUN_windows.bat🍓 Raspberry Pi:
cd Driver-Fatigue-Detector_Raspberry
chmod +x RUN_raspberry.sh
./RUN_raspberry.sh🔧 Or directly:
python main.py| Step | Action | Description |
|---|---|---|
| 1️⃣ | Registration/Login | Create an account or login through the web dashboard |
| 2️⃣ | Device Setup | Ensure your camera is connected and the AI module is running |
| 3️⃣ | Monitoring | The system will automatically detect and report drowsiness levels |
| 4️⃣ | Dashboard | View real-time statistics and historical data in the web interface |
| 5️⃣ | Alerts | System will trigger audio alerts when drowsiness is detected |
POST /api/auth/register
Content-Type: application/json
{
"email": "[email protected]",
"password": "securepassword",
"name": "John Doe",
"role": "driver"
}POST /api/auth/login
Content-Type: application/json
{
"email": "[email protected]",
"password": "securepassword"
}GET /api/auth/me
Authorization: Bearer <token>POST /api/devices/:id/data
Content-Type: application/json
{
"eye_closure": 0.8,
"drowsiness_level": "high",
"status": "drowsy",
"timestamp": "2025-01-09T12:00:00Z"
}GET /api/devices/:id/dataGET /api/devices/:id/history?limit=100POST /api/devices/:id/alert
Content-Type: application/json
{
"alert_type": "drowsiness_detected",
"severity": "high",
"timestamp": "2025-01-09T12:00:00Z"
}GET /api/devices/:id/alerts?limit=50GET /api/admin/overview
Authorization: Bearer <admin-token>GET /api/admin/drivers
Authorization: Bearer <admin-token>GET /api/admin/recent-alerts
Authorization: Bearer <admin-token>GET /api/healthKey parameters in core/detector.py:
EAR_THRESHOLD- Eye aspect ratio threshold (default: 0.25)FRAME_COUNT- Consecutive frames for drowsiness detectionALERT_DURATION- Alert sound duration
Environment variables in go-backend/.env:
- Database connection settings
- JWT secret key
- Server port
- Environment mode (development/production)
Environment variables in root .env:
VITE_API_URL- Backend API URL
FROM golang:1.21-alpine
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o main .
EXPOSE 8080
CMD ["./main"]- Build the binary:
cd go-backend
go build -o driver-drowsiness-backend main.go- Set environment variables
- Run the binary:
./driver-drowsiness-backendnpm run build- Connect your repository
- Set build command:
npm run build - Set output directory:
dist - Configure environment variables
- Install dependencies
- Set up auto-start service:
sudo systemctl enable driver-drowsiness.serviceUse NSSM (Non-Sucking Service Manager) to create a Windows service.
| Step | Action |
|---|---|
| 1️⃣ | Fork the repository |
| 2️⃣ | Create a feature branch |
| 3️⃣ | Make your changes |
| 4️⃣ | Submit a pull request |
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 Patchara Al-umaree, Thanapon Dongphuyaw, Disorn Suppartum
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
| Organization/Project | Contribution |
|---|---|
| 👁️ OpenCV Community | Computer vision tools and libraries |
| 🤖 MediaPipe Team | Face detection models and landmarks |
| ⚛️ React Community | Excellent frontend framework |
| 🐹 Go Community | Robust backend framework |
| 🌍 Open Source Contributors | All libraries that made this project possible |