-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
166 lines (118 loc) · 5.45 KB
/
Copy pathREADME
File metadata and controls
166 lines (118 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# 🪖 MTV Helmet Violation Detection
> **A customized ensemble model for automated traffic violation detection on motorized two-wheelers (MTVs) using YOLOv8 + YOLOv5 and a Streamlit web interface.**





---
## 📋 Table of Contents
- [Overview](#overview)
- [How It Works](#how-it-works)
- [Tech Stack](#tech-stack)
- [Getting Started](#getting-started)
- [Usage](#usage)
- [Limitations](#limitations)
- [Future Work](#future-work)
---
## Overview
The increasing number of motorized two-wheelers on roads has led to a rise in helmet-related traffic violations. Manual monitoring is time-consuming and inefficient.
This project provides a **web-based intelligent violation detection system** that automatically identifies helmet violations from uploaded images. It combines a multi-stage YOLOv8 + YOLOv5 detection pipeline with a simple Streamlit interface — no technical knowledge required to use it.
---
## How It Works
The system runs a six-stage detection pipeline on each uploaded image:
```
Image Upload
│
▼
YOLOv8 Object Detection ──→ Motorcycle boxes
│ └──→ Person boxes
▼
YOLOv5 Helmet Detection (full 640×640 image)
│ Returns "helmet" / "no-helmet" boxes + confidence
▼
Spatial Association
│ IoU overlap: motorcycle ↔ person ↔ helmet box
▼
Violation Classification
│ Helmet ✅ or No Helmet ❌ per rider
▼
Annotated Output + Violation Banner
```
**Step 1 — Image Upload**
The user uploads a traffic image (JPG, JPEG, or PNG) via the Streamlit interface.
**Step 2 — Motorcycle & Rider Detection**
`yolov8n.pt` detects all motorcycles and persons in the frame, returning bounding box coordinates for each.
**Step 3 — Helmet Detection**
A custom YOLOv5 model (`best.pt`, sourced from Hugging Face) runs inference on the full image resized to 640×640 — *not on cropped regions* — and returns `helmet` or `no-helmet` detections with confidence scores.
**Step 4 — Spatial Association**
Helmet detections are matched to rider detections via bounding-box IoU overlap. Each motorcycle is linked to the nearest overlapping person, and helmet status is resolved from the intersecting helmet box.
**Step 5 — Violation Classification**
Riders without a detected helmet are flagged as violations. Each motorcycle in the frame receives an individual status label, and a global violation flag is set.
**Step 6 — Output**
The processed image is displayed with colour-coded bounding boxes (green = helmet, red = no helmet), status labels, and a summary banner.
---
## Tech Stack
| Component | Technology |
|---|---|
| Language | Python 3.8+ |
| Web Interface | Streamlit |
| Object Detection | YOLOv8 (ultralytics) |
| Helmet Detection | YOLOv5 (custom fine-tuned `best.pt`) |
| Deep Learning | PyTorch |
| Image Processing | OpenCV |
| Image Handling | Pillow (PIL) |
| Numerical Computation | NumPy |
| Deployment | Streamlit Cloud / Hugging Face Spaces |
| Version Control | GitHub |
---
## Getting Started
### Prerequisites
- Python 3.8+
- Git
### Installation
```bash
# 1. Clone the repository
git clone https://github.com/GodzillaDcW/ProjectRepor.git
cd mtv-helmet-detection
# 2. Install dependencies
pip install -r requirements.txt
# 3. The app will auto-download the YOLOv5 repo and best.pt model on first run
```
### Run the app
```bash
streamlit run app.py
```
```
THIS BELOW LINK ONLY WORKS WHEN APP IS TURNED ON FROM STREAMLIT ACC,
ITS DISABLE AUTOMATICALLY IF INACTIVE FOR MORE THAN 2 HOURS
```
https://projectrepor-fjfh5wc6mh34bwjom2drcj.streamlit.app/
---
## Usage
1. Open the app in your browser.
2. Click **Browse files** and upload a traffic image (JPG, PNG, or JPEG).
3. The app will process the image and display:
- Bounding boxes around detected motorcycles and riders
- A `Helmet ✅` or `No Helmet ❌` label per motorcycle
- A **Violation Detected** or **No Violation** banner
---
## Limitations
- Detection accuracy depends on image quality and lighting conditions.
- The model (derived from a Construction PPE pretrained model) struggles with darker-coloured helmets in low-light conditions.
- Side-angle helmet views are often missed.
- Occluded helmets may not be detected reliably.
- Only static image uploads are supported — video is not yet implemented.
- Inference may be slow on low-end hardware due to the dual-model pipeline.
---
## Future Work
- [ ] Real-time video processing support
- [ ] Key-frame extraction for efficient video analysis
- [ ] Retraining on traffic-specific helmet datasets for improved accuracy
- [ ] Detection of additional violation types (e.g. phone use, overloading)
- [ ] Lightweight model variants for edge device deployment
---
## Conclusion
This project demonstrates a practical application of computer vision for automated road safety enforcement. Despite current limitations, the dual-model ensemble provides a scalable foundation for building more comprehensive intelligent traffic surveillance systems.
---
*Built with YOLOv8 · YOLOv5 · Streamlit · PyTorch*