-
Notifications
You must be signed in to change notification settings - Fork 0
/
gesture_detector.py
38 lines (33 loc) · 1.14 KB
/
gesture_detector.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
'''
Class responsible for detecting gestures.
'''
class GestureDetector:
def __init__(self, gestures=[]):
self._gestures = gestures
'''
Adds a gesture to be recognized
'''
def add_gesture(self, gesture):
self._gestures.append(gesture)
'''
searches for all gestures in the data using a threshold for the percentage, which is determined by inspection
'''
def find_gestures(self, data):
gestures = []
for row in data[::10]:
for gesture in self._gestures:
is_gesture, score = self.is_gesture(data, row[gesture._time_field], gesture)
if is_gesture:
print 'found', gesture, 'at', row[gesture._time_field], 'with score of', score
def is_gesture(self, data, start, gesture):
compare = data[(data[gesture._time_field] >= start) &
(data[gesture._time_field] <= start + gesture.get_max_gesture_time_length()) &
(start + gesture.get_max_gesture_time_length() <= data[gesture._time_field][-1])]
if len(compare) > 0:
score = gesture.compare(compare)
else:
score = 0
return score >= .5, score
'''GETTERS'''
def get_gestures(self):
return self._gestures