File size: 844 Bytes
3f3fff8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)