Skip to content

devkesav/Drowsy-Sentry-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›Œ AI Drowsiness & Yawning Detection System with Telegram Alerts

This project is a complete real-time drowsiness and yawn detection system built using OpenCV, MediaPipe, Tkinter GUI, and Telegram Bot for alert notifications. It includes:

  • Eye Aspect Ratio (EAR) and Mouth Aspect Ratio (MAR) calculations
  • TTS voice alerts
  • Pre- and post-alert video recording
  • Telegram alerts with 10s video
  • CUDA GPU acceleration (if available)

πŸ’Ύ Features

βœ… Real-time face mesh detection using MediaPipe βœ… EAR/MAR calculation for eye closure and yawning βœ… Auto video recording (5s before + 5s after alert) βœ… Telegram bot alert with video proof βœ… Tkinter-based GUI with live feed βœ… Text-to-speech (TTS) alerts βœ… GPU acceleration using OpenCV CUDA


πŸ“ Project Structure

.
β”œβ”€β”€ drowsy_detector.py       # Main source code (uploaded by user)
β”œβ”€β”€ README.md                # This file
└── /drowsy_video/           # Auto-saved alert videos

🧰 Requirements

Install all Python dependencies using:

pip install opencv-python mediapipe pyttsx3 python-telegram-bot Pillow

βœ… Optional for GUI support:

pip install tkinter

βœ… Optional for GPU acceleration:

pip install opencv-contrib-python

βš™οΈ Configuration

Open the drowsy_detector.py file and update the following:

TELEGRAM_TOKEN = '<YOUR_BOT_TOKEN>'
CHAT_ID = '<YOUR_TELEGRAM_CHAT_ID>'

If not using Telegram alerts, just leave TELEGRAM_TOKEN = ''.

βœ… Ensure the following directory exists:

mkdir -p /home/pi/drowsy_video

πŸš€ How to Run

On any PC with Python:

python drowsy_detector.py

You’ll see a GUI window with:

  • EAR/MAR values
  • Start/Stop buttons
  • Live video feed

πŸ“† Features in Action

Feature Description
🟒 Drowsy Detection Alerts if eyes closed for EYE_FRAMES
🟑 Yawn Detection Alerts if mouth open for MAR_FRAMES
πŸŽ₯ Video Recording 5 seconds before & after alert
πŸ—£οΈ TTS Audible alert
πŸ“€ Telegram Bot Sends video to your chat

πŸ’‘ Thresholds (tweak as needed)

EYE_THRESH = 0.28        # Eye Aspect Ratio
EYE_FRAMES = 51          # 1.7 seconds at 30 FPS

MAR_THRESH = 0.6         # Mouth Aspect Ratio
MAR_FRAMES = 60          # 2 seconds at 30 FPS

⚑ GPU Acceleration

If you have an NVIDIA GPU:

  • Uses cv2.cuda to process frames
  • Set CUDA device using cv2.cuda.setDevice(0)
  • Automatically falls back to CPU if CUDA not found

🧟 Telegram Bot Setup (Optional)

  1. Create bot using @BotFather
  2. Note down the BOT TOKEN
  3. Get your chat_id using this method

🚫 Exit & Cleanup

  • Clicking Exit or closing the GUI will:

    • Release camera
    • Stop TTS
    • Finalize video
    • Exit gracefully

🧠 Author

Created by Deventhira Kesavaraj BE.EEE, KPRIET Project: AI Drowsy Detection System with Telegram Alert Support


πŸ“Έ Sample Alert Message

πŸ›Œ ALERT: DROWSINESS DETECTED!
Capturing 10-second video...

πŸ”— Then sends the video via Telegram!

About

🚨 Real-time AI Drowsiness & Yawn Detection System using MediaPipe, OpenCV, and Telegram Bot. 🧠 Detects eye closure & yawns, records 10s video, sends TTS and Telegram alerts. πŸ’» Includes live GUI, GPU acceleration (CUDA), and smart alert logic.

Resources

License

Stars

Watchers

Forks

Contributors

Languages