Spaces:
Sleeping
Sleeping
from PIL import Image, ImageDraw | |
def draw_bounding_box(input_path, output_path): | |
# Open the image and convert to RGBA | |
image = Image.open(input_path).convert("RGBA") | |
# Get the bounding box of the non-blank area | |
bbox = image.getbbox() | |
if bbox: | |
# Create a copy of the image to draw on | |
draw_image = image.copy() | |
draw = ImageDraw.Draw(draw_image) | |
# Draw the bounding box | |
draw.rectangle(bbox, outline="red", width=3) | |
# Save the image with the bounding box | |
draw_image.save(output_path) | |
print(f"Processed image: Bounding box {bbox}") | |
else: | |
print("No non-blank area found in the image") | |
# Example usage | |
input_image = "bria_output/1000416735_02.png" | |
output_image = "bbox_image.png" | |
draw_bounding_box(input_image, output_image) | |