|
from PIL import Image, ImageDraw, ImageFont |
|
|
|
from physical_boxes_define import gdf |
|
|
|
|
|
def draw_bounding_boxes(image_path, gdf): |
|
image = Image.open(image_path+'bird.png').convert("RGB") |
|
|
|
draw = ImageDraw.Draw(image) |
|
|
|
|
|
|
|
font = ImageFont.truetype("assets/fonts/LiberationSans-Regular.ttf", |
|
20) |
|
|
|
|
|
|
|
|
|
|
|
for _, row in gdf.iterrows(): |
|
xmin, ymin, xmax, ymax = row['geometry'].bounds |
|
draw.rectangle([xmin, ymin, xmax, ymax], outline="purple", width=2) |
|
draw.text((xmin, ymin-22), row['name'], fill="black", font=font) |
|
|
|
image.save(image_path+'bird_boxed.png', "PNG") |
|
|
|
if __name__ == "__main__": |
|
draw_bounding_boxes('assets/images/', gdf) |