Skip to content

Repository files navigation

Helmet Detection — Safety Compliance System

Real-time helmet detection system using YOLOv8 that monitors live camera feeds, logs violations, captures snapshots, and dispatches automated email alerts to site managers.


How It Works

  1. YOLOv8 processes every webcam frame to detect person, worker, helmet, and hardhat classes
  2. For each detected person, it checks if a helmet bounding box overlaps the head region (top 40% of the person box)
  3. If no helmet is found on a person → violation is triggered:
    • Snapshot is saved to images/violations/
    • OCR runs on the person crop to read a chest/suit ID
    • Email alert with the snapshot is sent to the manager (throttled to once every 20 seconds)

Tech Stack

Component Tool
Object detection YOLOv8 (Ultralytics) — model/best.pt
Vision processing OpenCV
Web server Flask
Chest number OCR EasyOCR / custom (ocr_utils.py)
Email alerts Python smtplib + Gmail SMTP
Frontend Vanilla HTML / CSS / JS

Project Structure

Helmet-Detection/
├── app.py                        # Flask server + detection pipeline
├── email_utils.py                # Gmail SMTP alert sender
├── ocr_utils.py                  # Chest number OCR extractor
├── cleanup.py                    # Auto-delete old violation images
├── model/
│   └── best.pt                   # Fine-tuned YOLOv8 helmet model
├── images/violations/            # Auto-saved violation snapshots
├── logs/violations.csv           # Violation event log
├── templates/index.html          # Professional dashboard UI
├── static/style.css              # Custom styling
├── Dockerfile                    # Containerization config
├── render.yaml                   # Deployment specification
├── .env.example                  # Environment variables template
└── requirements.txt              # Project dependencies

Setup & Run

1. Install dependencies

pip install -r requirements.txt

2. Configure Environment (Optional)

Copy .env.example to .env and set your credentials:

cp .env.example .env

3. Run Application

python app.py

3. Open dashboard

http://localhost:5000

Dashboard Features

Feature Details
Live detection feed YOLOv8 bounding boxes with confidence %
Stats bar Uptime · Helmets detected · Violations · Persons tracked
Event log Timestamped, filterable (All / Violations / Safe)
Violation gallery Last 6 snapshots, click to enlarge
Alert banner Flashes on new violation

Email Alerts

Configure credentials in email_utils.py:

EMAIL_ADDRESS  = 'your@gmail.com'
EMAIL_PASSWORD = 'your_app_password'   # Gmail App Password (not your real password)
MANAGER_EMAIL  = 'manager@company.com'

Generate a Gmail App Password: Google Account → Security → 2-Step Verification → App Passwords


Model Details

  • Base: yolov8n.pt (YOLOv8 Nano)
  • Fine-tuned on: helmet / hardhat / person / worker dataset (data.yaml)
  • Inference threshold: 0.5 confidence
  • Helmet-on-head check: helmet box must be within the top 40% of the person box

Configuration (app.py)

Constant Default Description
MODEL_PATH model/best.pt Path to YOLO weights
MANAGER_EMAIL gmail address Alert recipient
VIOLATION_FOLDER images/violations Snapshot save path
Email throttle 20 seconds Min gap between email alerts
Confidence threshold 0.5 Min detection confidence

Requirements

  • Python 3.10+
  • Webcam or RTSP camera
  • Gmail account with App Password enabled (for email alerts)

Author

Harsh Ramesh Nerkar
B.Tech CSE 2026 | AI/ML Engineer
Email: harshrameshnerkar@gmail.com

About

Real-time Helmet & Safety Gear Detection system using YOLOv8, OpenCV, EasyOCR, and Flask with automated email alerts and live violation tracking dashboard.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages