-
Notifications
You must be signed in to change notification settings - Fork 0
/
supervisor_label.py
50 lines (40 loc) · 1.04 KB
/
supervisor_label.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
47
48
49
50
import cv2
import os
import random
from glob import glob
from shutil import copyfile
target_directory = 'labels'
labels = {
'm': 'male',
'f': 'female',
}
def random_string():
return str(random.randint(100000, 999999))
for value in labels.values():
path = os.path.join(target_directory, value)
if not os.path.exists(path):
os.makedirs(path)
image_list = glob(os.path.join('images', '*.jpg'))
index = 0
while index < image_list:
image_file = image_list[index]
target_file = os.path.basename(image_file)
image = cv2.imread(image_file)
image = cv2.resize(image, (256, 256))
cv2.imshow('image', image)
key = cv2.waitKey(0) & 0xFF
if key == 81: # left arrow
index -= 1
if index < 0:
index = 0
elif key == ord('q'):
break
elif chr(key) in labels:
path = os.path.join(
target_directory,
labels[chr(key)],
target_file,
)
copyfile(image_file, path)
os.remove(image_file)
index += 1