yihong1120/Construction-Hazard-Detection
About
Enhances construction site safety using YOLO for object detection, identifying hazards like workers without helmets or safety vests, and proximity to machinery or vehicles. HDBSCAN clusters safety cone coordinates to create monitored zones. Post-processing algorithms improve detection accuracy.
AI & Machine LearningMeasured star growth
- in 24h
- 0
- in 7 days
- -2
- in 15 days
- -1
- in 1 month
- +2
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Original🇬🇧 English (UK) | 🇹🇼 繁體中文(台灣)

From a live camera feed, the system flags missing protective equipment, workers entering restricted areas, and workers getting too close to machinery or vehicles. Site teams can watch the annotated video, review saved images and receive alerts.
What It Detects
| Missing safety vest | Worker near machinery | Worker inside a restricted area |
|---|---|---|
![]() |
![]() |
![]() |
The rules also check for missing hard hats, workers near vehicles, and machinery or vehicles near utility poles. On-screen labels and notifications support Traditional Chinese, Simplified Chinese, English, French, Thai, Vietnamese, Indonesian and Japanese.
main.py Processing Workflow

main.py loads PostgreSQL or JSON configuration, supervises camera processes
and shared YOLO workers, and starts the outbox dispatcher. The workflow below
shows how those processes turn live video into detections, safety warnings,
recorded evidence, and notifications, from left to right.
flowchart LR
MAIN["main.py<br/>Configuration and process management"]
CAPTURE["Video capture<br/>RTSP / HTTP / local video"]
MAIN -. Start and supervise .-> CAPTURE
subgraph DETECTION["Detection and hazard analysis"]
YOLO["YOLO workers<br/>GPU object detection"]
RULES["Hazard analysis<br/>PPE, proximity and restricted areas"]
YOLO -->|Detection results| RULES
end
CAPTURE -->|Latest frames| YOLO
subgraph LIVE["Live video and warnings"]
MEDIA["Video publishing / MediaMTX<br/>Clean and annotated video"]
REDIS[("Redis<br/>Warning metadata")]
VIEW["Web / Flutter App<br/>Live video and warnings"]
MEDIA -->|HLS / WebRTC| VIEW
REDIS -->|Streaming Web API<br/>SSE / WebSocket| VIEW
end
CAPTURE -->|Clean video| MEDIA
RULES -->|Annotated video| MEDIA
RULES -->|Warning state| REDIS
subgraph EVIDENCE["Evidence storage and notifications"]
OUTBOX[("SQLite outbox<br/>Queued evidence and delivery retries")]
STORE["Violation Records API<br/>PostgreSQL records + image files"]
NOTIFY["FCM notifications<br/>Push to site members' devices"]
OUTBOX -->|Outbox dispatcher| STORE
STORE -->|Upload succeeds| NOTIFY
end
RULES -->|Eligible violation event| OUTBOX
classDef control fill:#eef2ff,stroke:#6366f1,color:#182b45
classDef video fill:#eaf1ff,stroke:#2563eb,color:#182b45
classDef detection fill:#e4f4f3,stroke:#087f8c,color:#182b45
classDef storage fill:#fff2df,stroke:#b45309,color:#182b45
class MAIN control
class CAPTURE,MEDIA,VIEW video
class YOLO,RULES,REDIS detection
class OUTBOX,STORE,NOTIFY storage
Quick Start
| Task | Guide |
|---|---|
| Connect live cameras using Python | Prepare Python, download weights and start the camera services |
| Run cameras with the standalone Rust pipeline | Capture and TensorRT inference · Rust API and pipeline release preview |
| Watch a stream or review an incident | Live viewing · Violation records · Flutter frontend |
| Understand how a frame becomes an alert | Python processing diagram · Evidence delivery and retries |
For the Python services, run uv sync --locked from the repository root on Linux x86_64 with CPython 3.15. Training, ONNX Runtime and TensorRT require additional dependencies. Python setup and native wheels
Try a safety rule on the CPU
This example passes one tracked detection to the Rust pipeline. It runs locally without a camera, model weights or a GPU. From the repository root on Linux, use Rust 1.93.1 and the FFmpeg development libraries listed in the build guide.
work_dir="$(mktemp -d)"
printf '%s\n' '{"tracked":[[0,0,10,20,0.9,2,0,0]],"reset":true,"rules":{"detect_no_safety_vest_or_helmet":true}}' > "$work_dir/input.jsonl"
cargo run --locked --manifest-path native/pipeline/Cargo.toml -- \
analyze --input "$work_dir/input.jsonl" --output "$work_dir/result.jsonl"
cat "$work_dir/result.jsonl"
The output records one missing hard hat under warning_no_hardhat. To run detection on actual footage, follow the TensorRT example using the included video.
Dataset and Models
Download annotated images from Roboflow and trained weights from Hugging Face. To train on your own footage, follow data augmentation, training and evaluation. Camera workers load weights through the published model catalogue.
Model class IDs and labels
0 Hardhat
1 Mask
2 NO-Hardhat
3 NO-Mask
4 NO-Safety Vest
5 Person
6 Safety Cone
7 Safety Vest
8 Machinery
9 Utility Pole
10 Vehicle
Development and operations
- Source modules and repository map
- Development checks and contribution guide
- Deployment and operations guide and configuration reference
Licence
This project is licensed under the AGPL-3.0 Licence.
Explore related projects
Loading…


