Create display_BB.py

#1
by jkushwaha - opened
Files changed (1) hide show
  1. display_BB.py +22 -0
display_BB.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw
2
+
3
+ def draw_bounding_boxes(image_path, boxes, labels):
4
+ image = Image.open(image_path)
5
+ draw = ImageDraw.Draw(image)
6
+
7
+ for box, label in zip(boxes, labels):
8
+ x_min, y_min, x_max, y_max = box
9
+ draw.rectangle([x_min, y_min, x_max, y_max], outline="red", width=2)
10
+ draw.text((x_min, y_min), label, fill="red")
11
+
12
+ # if save_path:
13
+ # image.save(save_path)
14
+
15
+ return image
16
+
17
+ # Example usage:
18
+ image_path = "example.jpg"
19
+ boxes = [(100, 100, 200, 200), (300, 300, 400, 400)] # Example bounding box coordinates
20
+ labels = ["Object 1", "Object 2"] # Example labels
21
+ output_image = draw_bounding_boxes(image_path, boxes, labels, save_path="output.jpg")
22
+ output_image.show()