Spaces:
Runtime error
Runtime error
File size: 1,120 Bytes
eb0e26a 27d8552 d761fce 27d8552 d761fce 27d8552 d761fce 27d8552 d643db8 27d8552 d761fce 610526e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import cv2
def overlay_boxes(frame, detected_items):
"""
Add overlays (bounding boxes and labels) to a frame.
Args:
frame: Input frame (numpy array)
detected_items: List of detection dictionaries
Returns:
numpy array: Frame with overlays
"""
for item in detected_items:
if "coordinates" not in item or "label" not in item:
continue
x_min, y_min, x_max, y_max = item["coordinates"]
label = item["label"]
# Choose color based on type
if item["type"] == "crack":
color = (255, 0, 0) # Red for cracks
elif item["type"] == "pothole":
color = (255, 165, 0) # Orange for potholes
else:
color = (0, 255, 0) # Green for other objects
cv2.rectangle(frame, (x_min, y_min), (x_max, y_max), color, 2)
# Add severity if present
if "severity" in item:
label += f" - Severity: {item['severity'].capitalize()}"
cv2.putText(frame, label, (x_min, y_min - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
return frame |