Created
November 19, 2019 11:38
-
-
Save gguuss/d7c7814e5bc7fdf8ee3fc32d5d06d6ea to your computer and use it in GitHub Desktop.
Label and draw a bounding box around an image target
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def draw_obj(image_file, text, vects): | |
"""Draw a border around the image using the label and vector list.""" | |
from PIL import Image, ImageDraw, ImageFont | |
im = Image.open(image_file) | |
w = im.width | |
h = im.height | |
draw = ImageDraw.Draw(im) | |
fnt = ImageFont.truetype('Verdana.ttf', 40) | |
draw.text( | |
(vects[0].x * w, vects[0].y*h), | |
text, | |
font=fnt, | |
fill=(255,255,0,255)) | |
print('1111') | |
draw.polygon([ | |
vects[0].x * w, vects[0].y * h, | |
vects[1].x * w, vects[1].y * h, | |
vects[2].x * w, vects[2].y * h, | |
vects[3].x * w, vects[3].y * h], None, 'red') | |
im.save(image_file, 'JPEG') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment