From e26f1fe806c5938e8008b83ece1e00476a11ff97 Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Thu, 26 Sep 2024 12:50:52 -0400 Subject: [PATCH] Delete file --- demo/draw_boxes.py | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 demo/draw_boxes.py diff --git a/demo/draw_boxes.py b/demo/draw_boxes.py deleted file mode 100644 index a1552b0..0000000 --- a/demo/draw_boxes.py +++ /dev/null @@ -1,45 +0,0 @@ -from PIL import ImageDraw, ImageFont # type: ignore -import colorsys - - -def get_color(label): - # Simple hash function to generate consistent colors for each label - hash_value = hash(label) - hue = (hash_value % 100) / 100.0 - saturation = 0.7 - value = 0.9 - rgb = colorsys.hsv_to_rgb(hue, saturation, value) - return tuple(int(x * 255) for x in rgb) - - -def draw_bounding_boxes(image, results: dict, model, threshold=0.3): - draw = ImageDraw.Draw(image) - font = ImageFont.load_default() - - for score, label_id, box in zip( - results["scores"], results["labels"], results["boxes"] - ): - if score > threshold: - label = model.config.id2label[label_id.item()] - box = [round(i, 2) for i in box.tolist()] - color = get_color(label) - - # Draw bounding box - draw.rectangle(box, outline=color, width=3) # type: ignore - - # Prepare text - text = f"{label}: {score:.2f}" - text_bbox = draw.textbbox((0, 0), text, font=font) - text_width = text_bbox[2] - text_bbox[0] - text_height = text_bbox[3] - text_bbox[1] - - # Draw text background - draw.rectangle( - [box[0], box[1] - text_height - 4, box[0] + text_width, box[1]], # type: ignore - fill=color, # type: ignore - ) - - # Draw text - draw.text((box[0], box[1] - text_height - 4), text, fill="white", font=font) - - return image