-
Notifications
You must be signed in to change notification settings - Fork 690
/
Gesture_Record.py
125 lines (75 loc) · 2.02 KB
/
Gesture_Record.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# coding: utf-8
# In[77]:
import os
import cv2
import time
# In[78]:
gesture_name = raw_input("Enter Gesture Name ")
# In[79]:
images = []
num_frames = 60
# In[80]:
capture_start = False
cv2.namedWindow("Video", cv2.WINDOW_NORMAL)
vc = cv2.VideoCapture(0)
vc.set(cv2.CAP_PROP_FPS, 5)
rval, frame = vc.read()
cnt = 0
while True:
if frame is not None:
frame = cv2.flip(frame, 1)
cv2.imshow("Video", frame)
rval, frame = vc.read()
keypress = cv2.waitKey(1)
if keypress == ord('q'):
break
elif keypress == ord('c'):
capture_start = True
if ( capture_start ):
img = cv2.flip(frame, 1)
#img = cv2.cvtColor( img, cv2.COLOR_RGB2BGR )
images.append(img)
cnt += 1
if ( cnt > num_frames ):
break
vc.release()
cv2.destroyAllWindows()
cv2.waitKey(1)
# In[81]:
if len(images) == 0:
print(" ERROR !! No Frames Recorded" )
exit()
# In[83]:
last_num = 0
folder_name = gesture_name
gestures_rec = os.listdir('./')
for i in gestures_rec:
if i[0] == '.':
continue
if '_'.join( i.split('_')[:-1] ) == gesture_name:
last_num = max(last_num, int( i.split('_')[-1] ) )
last_num += 1
folder_name = gesture_name + '_' + str(last_num)
try:
print('[i] Creating directory {}...'.format(folder_name))
os.makedirs(folder_name)
except (IOError) as e:
print('[!]', str(e))
exit()
# In[84]:
print ("[i] Creating Video")
output = './' + folder_name + '/output.mp4'
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Be sure to use lower case
out = cv2.VideoWriter(output, fourcc, 5.0, (images[0].shape[1], images[0].shape[0]) )
for image in images:
f = image
#print (f.shape)
out.write(f) # Write out frame to video
#cv2.imshow('video',frame)
if (cv2.waitKey(1) & 0xFF) == ord('q'): # Hit `q` to exit
break
# Release everything if job is finished
out.release()
cv2.destroyAllWindows()
# In[ ]:
print ("Output Video is in", output)