何をしたいか
メモ。
更新
- 20200116
- y座標が0に近い時でも画面内にラベルを表示できるようにした
結果のBBをPIL画像に表示する関数
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()