-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.py
More file actions
51 lines (40 loc) · 1.5 KB
/
handler.py
File metadata and controls
51 lines (40 loc) · 1.5 KB
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
import math
class handler:
def __init__(self):
self.left_hand = hand("left")
self.right_hand = hand("right")
self.hand_dict = {"left": self.left_hand, "right": self.right_hand}
def update(self, handedness, landmarks, draw):
i = 0
for hand_landmarks in landmarks:
for id, lm in enumerate(hand_landmarks.landmark):
self.hand_dict.get(self.getLabels(handedness)[i]).updatePoints([lm.x, lm.y, lm.z])
i+=1
draw(hand_landmarks)
self.left_hand.updateRadii()
self.right_hand.updateRadii()
#label the order which the hands are presented by mediapipe handedness
def getLabels(self, handedness):
return ['left' if label.classification[0].index else 'right' for label in handedness]
class hand:
def __init__(self, name):
self.points = []
self.radii = []
self.temp = []
self.name = name
def getList(self):
cord_list = []
index = 0
for radius in self.radii:
cord_list.append( [index, radius] )
index += 1
return cord_list
def updatePoints(self, point):
self.points.append(point)
def updateRadii(self):
self.radii = self.norm([math.dist(point, self.points[0]) for point in self.points])
self.temp = self.points
self.points = []
#normalize cords
def norm(self, cords):
return [float(i)/max(cords) for i in cords]