Spaces:
Sleeping
Sleeping
| import cv2 | |
| def overlay_boxes(frame, items): | |
| for item in items: | |
| box = item['box'] | |
| x_min, y_min, x_max, y_max = map(int, box) | |
| if item['type'] == 'crack': | |
| severity = item['severity'] | |
| color = (0, 0, 255) if severity == 'Severe' else (0, 255, 255) if severity == 'Moderate' else (0, 255, 0) | |
| label = severity | |
| elif item['type'] == 'pothole': | |
| color = (255, 0, 0) # Blue for potholes | |
| label = "Pothole" | |
| else: | |
| color = (255, 0, 255) # Magenta for objects | |
| label = item['label'] | |
| cv2.rectangle(frame, (x_min, y_min), (x_max, y_max), color, 2) | |
| cv2.putText(frame, label, (x_min, y_min - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2) | |
| return frame | |