File size: 1,213 Bytes
0b20e39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from PIL import Image, ImageDraw, ImageFont

def display_bbox_and_label(image, bbox, label):
    # Open the image
    # image = Image.open(image_path)

    # Initialize the drawing context
    draw = ImageDraw.Draw(image)

    # Define font and font size
    # font = ImageFont.load_default()
    font = ImageFont.load_default().font_variant(size=18)

    # Draw bounding box on the image
    draw.rectangle(bbox, outline="red", width=5)

    # Draw label text on the image
    draw.text((bbox[0], bbox[1] - 15), label, fill="green", font=font)

    # Display the image
    return image

# Example usage
# image_path = 'example_image.jpg'  # Path to your image file
# bounding_box = (100, 100, 300, 300)  # Define bounding box as (x_min, y_min, x_max, y_max)
# label = "Object"  # Define label for the bounding box
# display_bbox_and_label(image_path, bounding_box, label)

layout_results = layout_predictions[0]
for i in range(len(layout_results.bboxes)):
    b_box = layout_results.bboxes[i].bbox
    label = layout_results.bboxes[i].label
    image = display_bbox_and_label(image, b_box, label)
# display_bbox_and_label(image, layout_results.bboxes[3].bbox, layout_results.bboxes[3].label)
# layout_predictions