-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdisplay_all_gestures.py
47 lines (40 loc) · 1.02 KB
/
display_all_gestures.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
import cv2, os, random
import numpy as np
def get_image_size():
img = cv2.imread('emnist-dataset/1/29.jpg', 0)
return img.shape
gestures = os.listdir('emnist-dataset/')
gestures.sort(key = int)
begin_index = 1
end_index = 6
image_x, image_y = get_image_size()
if len(gestures)%5 != 0:
rows = int(len(gestures)/5)+1
else:
rows = int(len(gestures)/5)
full_img = None
for i in range(rows):
col_img = None
for j in range(begin_index, end_index):
img_path = "emnist-dataset/%s/" % (j)
try:
random_img = os.listdir(img_path)[random.randint(1,15)]
except:
random_img = ""
img_path += random_img
img = cv2.imread(img_path, 0)
if np.any(img == None):
img = np.zeros((image_y, image_x), dtype = np.uint8)
if np.any(col_img == None):
col_img = img
else:
col_img = np.hstack((col_img, img))
begin_index += 5
end_index += 5
if np.any(full_img == None):
full_img = col_img
else:
full_img = np.vstack((full_img, col_img))
cv2.imshow("gestures", full_img)
cv2.imwrite('full_img.jpg', full_img)
cv2.waitKey(0)