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) | |
| obj_id = item['id'] | |
| if item['type'] == 'crack': | |
| severity = item['severity'] | |
| if severity == 'Severe': | |
| color = (0, 0, 255) # Dark red | |
| elif severity == 'Moderate': | |
| color = (50, 50, 255) # Medium red | |
| else: | |
| color = (100, 100, 255) # Light red | |
| label = f"Crack ID:{obj_id} {item['confidence']*100:.1f}% ({severity})" | |
| else: # Pothole | |
| severity = item['severity'] | |
| if severity == 'Severe': | |
| color = (255, 0, 0) # Dark blue | |
| elif severity == 'Moderate': | |
| color = (255, 50, 50) # Medium blue | |
| else: | |
| color = (255, 100, 100) # Light blue | |
| label = f"Pothole ID:{obj_id} {item['confidence']*100:.1f}% ({severity})" | |
| cv2.rectangle(frame, (x_min, y_min), (x_max, y_max), color, 4) | |
| cv2.putText(frame, label, (x_min, y_min - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.7, color, 2) | |
| return frame |