hadiyya commited on
Commit
3d1a9bc
Β·
verified Β·
1 Parent(s): d3ff2ec

Create draw_boxes.py

Browse files
Files changed (1) hide show
  1. draw_boxes.py +22 -0
draw_boxes.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import ImageDraw
2
+
3
+ def draw_bounding_boxes(image, boxes, model, conf_threshold):
4
+ """
5
+ Draw bounding boxes on the image.
6
+
7
+ Args:
8
+ image (PIL.Image): The input image.
9
+ boxes (list): List of bounding boxes with confidence scores.
10
+ model: The object detection model (not used in this basic implementation).
11
+ conf_threshold (float): Confidence threshold for filtering boxes.
12
+
13
+ Returns:
14
+ PIL.Image: The image with bounding boxes drawn.
15
+ """
16
+ draw = ImageDraw.Draw(image)
17
+ for box in boxes:
18
+ if box["score"] >= conf_threshold:
19
+ x_min, y_min, x_max, y_max = box["box"]
20
+ draw.rectangle([x_min, y_min, x_max, y_max], outline="red", width=3)
21
+ draw.text((x_min, y_min), f"{box['label']} {box['score']:.2f}", fill="red")
22
+ return image