Create image_display_with bbox.py
Browse files1234567891011121314151617181920212223242526272829303132333435from 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_predictionsimage_display_with bbox.pyAdded+35