Skip to content

Commit 60a5a4a

Browse files
authored
Add files via upload
1 parent 9a84f04 commit 60a5a4a

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

display_all_gestures.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import cv2, os, random
2+
import numpy as np
3+
4+
def get_image_size():
5+
img = cv2.imread('gestures/0/100.jpg', 0)
6+
return img.shape
7+
8+
gestures = os.listdir('gestures/')
9+
gestures.sort(key = int)
10+
begin_index = 0
11+
end_index = 5
12+
image_x, image_y = get_image_size()
13+
14+
if len(gestures)%5 != 0:
15+
rows = int(len(gestures)/5)+1
16+
else:
17+
rows = int(len(gestures)/5)
18+
19+
full_img = None
20+
for i in range(rows):
21+
col_img = None
22+
for j in range(begin_index, end_index):
23+
img_path = "gestures/%s/%d.jpg" % (j, random.randint(1, 1200))
24+
img = cv2.imread(img_path, 0)
25+
if np.any(img == None):
26+
img = np.zeros((image_y, image_x), dtype = np.uint8)
27+
if np.any(col_img == None):
28+
col_img = img
29+
else:
30+
col_img = np.hstack((col_img, img))
31+
32+
begin_index += 5
33+
end_index += 5
34+
if np.any(full_img == None):
35+
full_img = col_img
36+
else:
37+
full_img = np.vstack((full_img, col_img))
38+
39+
40+
cv2.imshow("gestures", full_img)
41+
cv2.imwrite('full_img.jpg', full_img)
42+
cv2.waitKey(0)

load_images.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import cv2
2+
from glob import glob
3+
import numpy as np
4+
import random
5+
from sklearn.utils import shuffle
6+
import pickle
7+
import os
8+
9+
def pickle_images_labels():
10+
images_labels = []
11+
images = glob("gestures/*/*.jpg")
12+
images.sort()
13+
for image in images:
14+
print(image)
15+
label = image[image.find(os.sep)+1: image.rfind(os.sep)]
16+
img = cv2.imread(image, 0)
17+
images_labels.append((np.array(img, dtype=np.uint8), int(label)))
18+
return images_labels
19+
20+
images_labels = pickle_images_labels()
21+
images_labels = shuffle(shuffle(shuffle(shuffle(images_labels))))
22+
images, labels = zip(*images_labels)
23+
print("Length of images_labels", len(images_labels))
24+
25+
train_images = images[:int(5/6*len(images))]
26+
print("Length of train_images", len(train_images))
27+
with open("train_images", "wb") as f:
28+
pickle.dump(train_images, f)
29+
del train_images
30+
31+
train_labels = labels[:int(5/6*len(labels))]
32+
print("Length of train_labels", len(train_labels))
33+
with open("train_labels", "wb") as f:
34+
pickle.dump(train_labels, f)
35+
del train_labels
36+
37+
test_images = images[int(5/6*len(images)):int(11/12*len(images))]
38+
print("Length of test_images", len(test_images))
39+
with open("test_images", "wb") as f:
40+
pickle.dump(test_images, f)
41+
del test_images
42+
43+
test_labels = labels[int(5/6*len(labels)):int(11/12*len(images))]
44+
print("Length of test_labels", len(test_labels))
45+
with open("test_labels", "wb") as f:
46+
pickle.dump(test_labels, f)
47+
del test_labels
48+
49+
val_images = images[int(11/12*len(images)):]
50+
print("Length of test_images", len(val_images))
51+
with open("val_images", "wb") as f:
52+
pickle.dump(val_images, f)
53+
del val_images
54+
55+
val_labels = labels[int(11/12*len(labels)):]
56+
print("Length of val_labels", len(val_labels))
57+
with open("val_labels", "wb") as f:
58+
pickle.dump(val_labels, f)
59+
del val_labels

0 commit comments

Comments
 (0)