[PYTHON] Script example to display BoundingBox with PIL

What do you want to do

Note.

update

A function that displays the resulting BB in a PIL image

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)

sample

lena_std.jpglena_eye.jpg

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

Script example to display BoundingBox with PIL
[Blender] How to set shape_key with script
How to display python Japanese with lolipop
I made a script to display emoji
Sample program to display video with PyQt
I want to display multiple images with matplotlib.
[Cocos2d-x 3.0] How to automate Script Binding with binding-generator
Script to tweet with multiples of 3 and numbers with 3 !!
[Improved version] Script to monitor CPU with Python
How to display images continuously with matplotlib Note
Python script to get note information with REAPER
How to add help to HDA (with Python script bonus)
Schema-driven development with Responder: Try to display Swagger UI
It's too troublesome to display Japanese with Vim's python3.
Example of pytest environment to fix database with Docker
Display / update the graph according to the input with PySimpleGui
Python> function> Docstrings> Description to display with help () / .__ doc__
PIL installation with pip
Convert 202003 to 2020-03 with pandas
3D display with plotly
Taskbar display with tqdm
Image Processing with PIL
Try to display various information useful for debugging with python
[Linux] Copy data from Linux to Windows with a shell script
[Ev3dev] How to display bmp image on LCD with python
Convert color space from RGB to CIELAB with PIL (Pillow)
Create an example game-like stage with just the Blender 2.80 script
Convert images to sepia toning with PIL (Python Imaging Library)
How to display a list of installable versions with pyenv
"Deep copy" and "Shallow copy" to understand with the smallest example