yihong1120/Construction-Hazard-Detection
关于
使用 YOLO 进行目标检测,提升施工现场安全,并识别未佩戴安全帽或未穿安全背心的工人,以及工人与机械或车辆距离过近等隐患。HDBSCAN 对安全锥坐标进行聚类,生成监控区域。后处理算法可提高检测准确率。
人工智能与机器学习实测星标增长
- 24小时
- 0
- 7天
- -1
- 15天
- -1
- 1个月
- +1
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文🇬🇧 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.
探索相关项目
加载中…


