Spaces:
Runtime error
Runtime error
| import supervision as sv | |
| from PIL import Image | |
| def annotate_with_boxes(image: Image, detections: sv.Detections) -> Image: | |
| annotated_image = image.copy() | |
| thickness = sv.calculate_optimal_line_thickness(resolution_wh=image.size) | |
| text_scale = sv.calculate_optimal_text_scale(resolution_wh=image.size) | |
| bounding_box_annotator = sv.BoundingBoxAnnotator( | |
| color_lookup=sv.ColorLookup.INDEX, thickness=thickness) | |
| label_annotator = sv.LabelAnnotator( | |
| color_lookup=sv.ColorLookup.INDEX, | |
| text_scale=text_scale, | |
| text_thickness=thickness) | |
| annotated_image = bounding_box_annotator.annotate(annotated_image, detections) | |
| annotated_image = label_annotator.annotate(annotated_image, detections) | |
| return annotated_image | |