Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,7 +53,7 @@ CONFIG = {
|
|
| 53 |
},
|
| 54 |
"PUBLIC_URL_BASE": "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo2/resolve/main/static/output/",
|
| 55 |
"CONFIDENCE_THRESHOLDS": {
|
| 56 |
-
"no_helmet": 0.
|
| 57 |
"no_harness": 0.4,
|
| 58 |
"unsafe_posture": 0.4,
|
| 59 |
"unsafe_zone": 0.4,
|
|
@@ -422,11 +422,13 @@ def process_video(video_data):
|
|
| 422 |
|
| 423 |
detection["worker_id"] = worker_id
|
| 424 |
|
| 425 |
-
# Track helmet violations
|
| 426 |
if detection["violation"] == "no_helmet":
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
|
|
|
|
|
|
| 430 |
else:
|
| 431 |
violations.append(detection)
|
| 432 |
|
|
@@ -441,10 +443,11 @@ def process_video(video_data):
|
|
| 441 |
# Confirm helmet violations (require multiple detections)
|
| 442 |
for worker_id, detections in helmet_violations.items():
|
| 443 |
if len(detections) >= CONFIG["MIN_VIOLATION_FRAMES"]:
|
|
|
|
| 444 |
best_detection = max(detections, key=lambda x: x["confidence"])
|
| 445 |
violations.append(best_detection)
|
| 446 |
|
| 447 |
-
# Capture snapshot
|
| 448 |
cap = cv2.VideoCapture(video_path)
|
| 449 |
cap.set(cv2.CAP_PROP_POS_FRAMES, best_detection["frame"])
|
| 450 |
ret, snapshot_frame = cap.read()
|
|
|
|
| 53 |
},
|
| 54 |
"PUBLIC_URL_BASE": "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo2/resolve/main/static/output/",
|
| 55 |
"CONFIDENCE_THRESHOLDS": {
|
| 56 |
+
"no_helmet": 0.75, # Increased for stricter helmet detection
|
| 57 |
"no_harness": 0.4,
|
| 58 |
"unsafe_posture": 0.4,
|
| 59 |
"unsafe_zone": 0.4,
|
|
|
|
| 422 |
|
| 423 |
detection["worker_id"] = worker_id
|
| 424 |
|
| 425 |
+
# Track helmet violations with stricter criteria
|
| 426 |
if detection["violation"] == "no_helmet":
|
| 427 |
+
# Only include high-confidence no_helmet detections
|
| 428 |
+
if conf >= CONFIG["CONFIDENCE_THRESHOLDS"]["no_helmet"]:
|
| 429 |
+
if worker_id not in helmet_violations:
|
| 430 |
+
helmet_violations[worker_id] = []
|
| 431 |
+
helmet_violations[worker_id].append(detection)
|
| 432 |
else:
|
| 433 |
violations.append(detection)
|
| 434 |
|
|
|
|
| 443 |
# Confirm helmet violations (require multiple detections)
|
| 444 |
for worker_id, detections in helmet_violations.items():
|
| 445 |
if len(detections) >= CONFIG["MIN_VIOLATION_FRAMES"]:
|
| 446 |
+
# Select the detection with the highest confidence
|
| 447 |
best_detection = max(detections, key=lambda x: x["confidence"])
|
| 448 |
violations.append(best_detection)
|
| 449 |
|
| 450 |
+
# Capture snapshot for confirmed no_helmet violation
|
| 451 |
cap = cv2.VideoCapture(video_path)
|
| 452 |
cap.set(cv2.CAP_PROP_POS_FRAMES, best_detection["frame"])
|
| 453 |
ret, snapshot_frame = cap.read()
|