Note.
def show_bb(img, x, y, w, h, text, textcolor, bbcolor):
draw = ImageDraw.Draw(img)
text_w, text_h = draw.textsize(text)
label_y = y if y <= text_h else y - text_h
draw.rectangle((x, label_y, x+w, label_y+h), outline=bbcolor)
draw.rectangle((x, label_y, x+text_w, label_y+text_h), outline=bbcolor, fill=bbcolor)
draw.text((x, label_y), text, fill=textcolor)
↓
from PIL import Image, ImageDraw
img = Image.open(path_to_image)
show_bb(img, 244, 249, 47, 30, "eye", (255, 255, 255), (255, 0, 0))
img.show()
Recommended Posts