Skip to content
프로젝트

yihong1120/Construction-Hazard-Detection

GitHub에서 보기

소개

YOLO 객체 탐지로 건설 현장의 안전을 강화하고, 안전모나 안전 조끼를 착용하지 않은 작업자와 기계 또는 차량에 너무 가까이 있는 작업자 등의 위험 요소를 감지합니다. HDBSCAN으로 안전 콘 좌표를 군집화해 모니터링 구역을 만들고, 후처리 알고리즘으로 탐지 정확도를 높입니다.

AI 및 머신러닝

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
-1
in 15 days
-1
in 1 month
+1

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

🇬🇧 English (UK) | 🇹🇼 繁體中文(台灣)

Construction Hazard Detection
Python 3.15 Ultralytics 8.4.183 HDBSCAN sklearn FastAPI 0.156.0 redis-py 8.1.0 Docker Codecov Download Dataset from Roboflow Hugging Face Model Repo

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
A worker marked No-Safety Vest A proximity warning beside a boom lift A worker inside the pink zone outlined by traffic cones

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

From video sources to live viewing and notifications

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

Licence

This project is licensed under the AGPL-3.0 Licence.

관련 프로젝트 살펴보기

불러오는 중…