-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetected_fingers_live.py
40 lines (30 loc) · 992 Bytes
/
detected_fingers_live.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
import cv2
import mediapipe as mp
mp_drawing = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
with mp_hands.Hands(
static_image_mode=False,
max_num_hands=3,
min_detection_confidence=0.5) as hands:
while (True):
ret, frame = cap.read()
if ret == False:
break
height, width, _ = frame.shape
frame = cv2.flip(frame,1)
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = hands.process(frame_rgb)
print(results.multi_hand_landmarks)
if results.multi_hand_landmarks is not None:
for hand_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(
frame,
hand_landmarks,
mp_hands.HAND_CONNECTIONS
)
cv2.imshow("Frame", frame)
if cv2.waitKey(1) & 0xFF == 27:
break
cap.release()
cv2.destroyAllWindows()