forked from EvilPort2/Simple-OpenCV-Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_all_gestures.py
41 lines (34 loc) · 900 Bytes
/
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
import cv2, os, random
import numpy as np
def get_image_size():
img = cv2.imread('gestures/0/100.jpg', 0)
return img.shape
gestures = os.listdir('gestures/')
gestures.sort(key = int)
begin_index = 0
end_index = 5
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 = "gestures/%s/%d.jpg" % (j, random.randint(1, 1200))
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.waitKey(0)