-
Notifications
You must be signed in to change notification settings - Fork 0
/
Train-Gesture.py
46 lines (39 loc) · 928 Bytes
/
Train-Gesture.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
# Python file to train/calibrate the gestures
import serial
import time
import pickle
import sys
ser = serial.Serial('COM3', 9600)
i=0
a=[]
coordinates=[]
labels=[]
try:
with open('gesture_input','rb') as f:
coordinates=pickle.load(f)
with open('gesture_labels','rb') as f:
labels=pickle.load(f)
except:
pass
count=0
while(1):
b = ser.readline()
string_n = b.decode()
string = string_n.rstrip()
flt = float(string)
a.append(flt)
i+=1
if i==3:
i=0
coordinates.append([a[0],a[1],a[2]])
labels.append(sys.argv[1])
print([a[0],a[1],a[2]])
ser.write(bytes("Training Model",'utf-8'))
a.clear()
count+=1
if count>=50:
break
with open('gesture_input','wb') as f:
pickle.dump(coordinates,f)
with open('gesture_labels','wb') as f:
pickle.dump(labels,f)