Automatically detect whether workers on a construction site or factory floor are wearing the required PPE — hard hats, safety vests, and gloves — and alert supervisors in real time when violations occur.
What you will learn
- How to train a custom PPE detection model (hard hat, vest, no-hat, no-vest)
- How to detect multiple PPE classes simultaneously in one inference pass
- How to trigger alerts only after a sustained violation (avoiding false alarms)
- How to send email or MQTT alerts with a snapshot of the violation
- How to log all violations to a database with timestamp and camera ID
Step 1 — Run the PPE compliance demo
cd ~/tutorials/12-ppe-compliance
python3 ppe_monitor.py --source 0 --show --alert-threshold 3
The system detects people and immediately checks whether they have a hard hat (shown in green) or are missing one (shown in red). If a violation persists for 3 seconds it triggers an alert.
Step 2 — PPE detection classes
PPE_CLASSES = {
0: 'hard-hat', # ✅ compliant
1: 'no-hard-hat', # ❌ violation
2: 'safety-vest', # ✅ compliant
3: 'no-vest', # ❌ violation
4: 'gloves', # ✅ compliant
5: 'no-gloves' # ❌ violation
}
for box in results[0].boxes:
cls = int(box.cls)
conf = float(box.conf)
if cls in [1, 3, 5] and conf > 0.7: # violation detected
trigger_violation_alert(cls, frame)
Step 3 — Sustained violation alert (debounce)
from collections import defaultdict
import time
violation_start = defaultdict(lambda: None)
ALERT_AFTER_SECS = 3
def check_sustained_violation(person_id, is_violation):
if is_violation:
if violation_start[person_id] is None:
violation_start[person_id] = time.time()
elif time.time() - violation_start[person_id] > ALERT_AFTER_SECS:
send_alert(person_id)
violation_start[person_id] = None # reset
else:
violation_start[person_id] = None # clear if compliant
✅ Next: Tutorial 13 — Face Blur Privacy Pipeline | Back to Jetson Kit