-
Notifications
You must be signed in to change notification settings - Fork 1
/
hand_gestures.py
120 lines (91 loc) · 3.9 KB
/
hand_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
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
from pickle import FALSE
class Hand_Gestures():
def __init__(self, keypoints):
self.keypoints = keypoints
def thumbFingIn(self):
if self.keypoints[4][1]>self.keypoints[3][1]:
return True
else:
return False
def indexFingIn(self):
if self.keypoints[8][2]>self.keypoints[7][2]:
return True
else:
return False
def middleFingIn(self):
if self.keypoints[12][2]>self.keypoints[11][2]:
return True
else:
return False
def ringFingIn(self):
if self.keypoints[16][2]>self.keypoints[15][2]:
return True
else:
return False
def pinkieFingIn(self):
if self.keypoints[20][2]>self.keypoints[19][2]:
return True
else:
return False
def handClosed(self):
# Return True if hand gestures is open = clicking
# pt 12<11 (middle finger), pt 16<15 (ring finger)
if self.keypoints == []:
return False
else:
if self.keypoints[11][2]>self.keypoints[12][2] and self.keypoints[15][2]>self.keypoints[16][2]:
return True
else:
return False
def indexRingFingersDown(self):
if self.indexFingIn() and self.middleFingIn():
return True
else:
return False
def w(self): # up - okay sign
if self.indexFingIn() and not self.ringFingIn() and not self.pinkieFingIn() and not self.middleFingIn() and self.thumbFingIn():
return True
else: False
def w1(self): # up - okay sign
if self.indexFingIn() and self.ringFingIn() and self.pinkieFingIn() and self.middleFingIn() and self.thumbFingIn():
return True
else: False
def a(self): # left - peace sign
if not self.indexFingIn() and self.ringFingIn() and self.pinkieFingIn() and not self.middleFingIn() and self.thumbFingIn():
return True
else: False
def s(self): # down - ring and pinky down
if not self.indexFingIn() and self.ringFingIn() and self.pinkieFingIn() and not self.middleFingIn() and not self.thumbFingIn():
return True
else: False
def d(self): # right - four
if not self.indexFingIn() and not self.ringFingIn() and not self.pinkieFingIn() and not self.middleFingIn() and self.thumbFingIn():
return True
else: False
def space(self): # raises the middle finger
if self.indexFingIn() and self.ringFingIn() and self.pinkieFingIn() and not self.middleFingIn():
return True
else: False
def l_click(self): # left_click - pinky thumb
if self.indexFingIn() and self.ringFingIn() and not self.pinkieFingIn() and self.middleFingIn() and not self.thumbFingIn():
return True
else: False
def r_click(self): # right_click - 4th finger down
if not self.indexFingIn() and self.ringFingIn() and not self.pinkieFingIn() and not self.middleFingIn() and not self.thumbFingIn():
return True
else: False
def e(self): # inventory - fist
if self.indexFingIn() and self.ringFingIn() and self.pinkieFingIn() and self.middleFingIn() and self.thumbFingIn():
return True
else: False
def q(self): # drop item - L with index/thumb
if not self.indexFingIn() and self.ringFingIn() and self.pinkieFingIn() and self.middleFingIn() and not self.thumbFingIn():
return True
else: False
def inventory_scroll(self): # - thumbs points left
if self.indexFingIn() and self.ringFingIn() and self.pinkieFingIn() and self.middleFingIn() and not self.thumbFingIn():
return True
else: False
def cursor():
pass
#wasd, e (inventory), spacebar, left_key, right_key, inventory_scroll, cursor,