-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathhandtracking.py
More file actions
73 lines (41 loc) · 1.54 KB
/
handtracking.py
File metadata and controls
73 lines (41 loc) · 1.54 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import cv2
import mediapipe as mp
# Initialize Mediapipe Hand solution
mp_hands = mp.solutions.hands
hands = mp_hands.Hands(static_image_mode=False,
max_num_hands=2,
min_detection_confidence=0.1,
min_tracking_confidence=0.1)
mp_drawing = mp.solutions.drawing_utils
#open the camera
cap = cv2.VideoCapture(1)
# error check to make sure the camera is open
if not cap.isOpened():
print("Error")
exit()
#Main loop
while True:
#capture frame by frame from the camera
success, frame = cap.read()
if not success:
break
# Flip the frame horizontally
frame = cv2.flip(frame, 1)
# Convert the frame color from BGR to RGB
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Process the RGB frame with MediaPipe Hands
results = hands.process(rgb_frame)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
# Draw landmarks
mp_drawing.draw_landmarks(frame, hand_landmarks,mp_hands.HAND_CONNECTIONS)
# Draw the hand annotations on the frame.
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
#Draw landmarks
mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
# Display the resulting frame
cv2.imshow("Frame", frame)
cv2.waitKey(1)
cap.release()
cv2.destroyAllWindows()