-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
33 lines (25 loc) · 780 Bytes
/
main.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
import cv2
from cvzone.HandTrackingModule import HandDetector
from pynput.keyboard import Key, Controller
cap = cv2.VideoCapture(0)
cap.set(3, 320)
cap.set(4, 210)
detector = HandDetector(detectionCon= 0.7, maxHands= 1)
keyboard = Controller()
while True:
_, img = cap.read()
hands, img = detector.findHands(img)
if hands:
finger = detector.fingersUp(hands[0])
if finger == [0,0,0,0,0]:
keyboard.press(Key.left)
keyboard.release(Key.right)
elif finger == [1,1,1,1,1]:
keyboard.press(Key.right)
keyboard.release(Key.left)
else:
keyboard.release(Key.left)
keyboard.release(Key.right)
cv2.imshow(img)
if cv2.waitKey(1) == ord ("q"):
break