-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecognizer.py
34 lines (24 loc) · 1.05 KB
/
recognizer.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
import cv2
import mediapipe as mp
from mediapipe import *
upFal = [4, 8, 12, 16, 20]
cap = cv2.VideoCapture(0)
hands = mp.solutions.hands.Hands(static_image_mode = False,
max_num_hands = 1,
min_tracking_confidence = 0.5,
min_detection_confidence = 0.5)
mpDraw = mp.solutions.drawing_utils
while True:
_, img = cap.read()
img = cv2.flip(img, 1)
result = hands.process(img)
if result.multi_hand_landmarks:
for id, lm in enumerate(result.multi_hand_landmarks[0].landmark):
h, w, _ = img.shape
cx, cy = int(lm.x * w), int(lm.y * h)
cv2.circle(img, (cx, cy), 3, (255, 0, 0))
if id in upFal:
cv2.circle(img, (cx, cy), 20, (255, 255, 0))
mpDraw.draw_landmarks(img, result.multi_hand_landmarks[0], mp.solutions.hands.HAND_CONNECTIONS)
cv2.imshow("Frame", img)
cv2.waitKey(1)