Skip to content

Commit 61fc298

Browse files
committed
experimenting with handtracking
1 parent 4adc04d commit 61fc298

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

app/tracker.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def __init__(self):
4444
self.prev_cursor = [0,0]
4545
self.hand_x = 0
4646
self.hand_y = 0
47+
self.base_x = 0
48+
self.base_y = 0
4749

4850
def start(self):
4951
self.cap = VideoCapture(0)
@@ -85,21 +87,28 @@ def step(self):
8587
ret = self.hand.process(self.monitor.width,self.monitor.height,self.handsFinder.find(frame))
8688

8789
if ret:
88-
print(f"here: {ret}")
8990
cursor,_,_ = ret
9091
cursor[1] = cursor[2] * 1000
9192
dx,dy = cursor[0] - self.prev_cursor[0], cursor[1] - self.prev_cursor[1]
9293
self.prev_cursor[0], self.prev_cursor[1] = cursor[0], cursor[1]
9394
self.hand_x -= dx
9495
self.hand_y += dy
9596
else:
96-
print("set to zero")
9797
self.hand_x = 0
9898
self.hand_y = 0
99-
print(self.hand_x,self.hand_y)
99+
self.base_x = 0
100+
self.base_y = 0
100101

101102
return (event.point, cevent.point, event.blink, event.fixation, cevent.acceptance_radius, cevent.calibration_radius)
102103

103104
def getHand(self,base_x,base_y):
104105
print(self.hand_x,self.hand_y)
105-
return (base_x + self.hand_x, base_y + self.hand_y)
106+
107+
diff_base_x = abs(base_x - self.base_x)
108+
diff_base_y = abs(base_y - self.base_y)
109+
110+
if diff_base_x + diff_base_y > 500:
111+
self.base_x = base_x
112+
self.base_y = base_y
113+
114+
return (self.base_x + self.hand_x, self.base_y + self.hand_y)

0 commit comments

Comments
 (0)