Spaces:
Runtime error
Runtime error
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 |