-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhdcopy.py
50 lines (44 loc) · 1.37 KB
/
hdcopy.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
import cv2
from cvzone.HandTrackingModule import HandDetector
import keyboard, time
import math
cap = cv2.VideoCapture(0)
detector = HandDetector(detectionCon=0.8, maxHands=2)
t = 0.2
while True:
img = cap.read()[1]
hands = detector.findHands(img, draw=False)
if len(hands) == 2:
hand1 = hands[0]
fingers1 = detector.fingersUp(hand1)
hand2 = hands[1]
fingers2 = detector.fingersUp(hand2)
h1 = hand1['center']
h2 = hand2['center']
if h1[0] < h2[0]:
right = h1
left = h2
rf = fingers1
lf = fingers2
else:
right = h2
left = h1
rf = fingers2
lf = fingers1
s = math.atan((right[1] - left[1]) / (right[0] - left[0])) if (right[0] - left[0]) != 0 else 0
if s < -0.02:
keyboard.press('right')
time.sleep(abs(s*t))
keyboard.release('right')
elif s > 0.02:
keyboard.press('left')
time.sleep(abs(s*t))
keyboard.release('left')
if rf == [0, 0, 0, 0, 0]:
keyboard.press('space')
time.sleep(0.05)
keyboard.release('space')
if lf == [0, 0, 0, 0, 0]:
keyboard.press('down')
time.sleep(0.05)
keyboard.release('down')