-
Notifications
You must be signed in to change notification settings - Fork 0
/
chekframes.py
46 lines (35 loc) · 1.59 KB
/
chekframes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from PIL import Image, ImageDraw, ImageFont
import os
from pathlib import Path
import shutil
def draw(images_path, labels_path):
pa = Path.cwd() / 'data' / 'Helmetxy'
pal = Path(pa / labels_path)
#dir_list = glob.glob(os.path.join(f'{pa}/{labels_path}', f'*.txt'))
dir_list = sorted(pal.glob('*'))
for each in dir_list:
check(pa, images_path, pal, os.path.splitext(os.path.split(each)[1])[0])
def check(path, images_path, labels_path, file_name):
im = Image.open(f'{path}/{images_path}/{file_name}.jpg')
width, height = im.size
with open(f"{labels_path}/{file_name}.txt") as file:
fl = file.readlines()[0:]
for line in fl:
a = line.split()
x = float(a[1]) * width
y = float(a[2]) * height
wf = float(a[3]) * width
hf = float(a[4]) * height
myFont = ImageFont.truetype('arial.ttf', 15)
ImageDraw.Draw(im).text((x, y), a[0], font=myFont, fill=(255, 0, 0))
draw = ImageDraw.Draw(im)
draw.rectangle(((x - wf / 2), (y - hf / 2), (x + wf / 2), (y + hf / 2)), outline=(255, 255, 255), width=2)
im.save(f'{path}/t{file_name}.jpg', quality=95)
if __name__ == '__main__':
draw('images', 'lables')
# # Укажите путь к папке, которую нужно архивировать
# folder_path = Path.cwd() / 'data' / 'Helmetxy'
# # Укажите путь и имя архива
# archive_path = Path.cwd() / 'data' / 'Helmetxy'
# # Создайте архив
# shutil.make_archive(archive_path, 'zip', folder_path)