Spaces:
Running
on
Zero
Running
on
Zero
File size: 780 Bytes
39bd209 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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 |