-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhand_tracking.py
More file actions
34 lines (27 loc) · 879 Bytes
/
hand_tracking.py
File metadata and controls
34 lines (27 loc) · 879 Bytes
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
import time as t
cap = cv2.VideoCapture(0)
mphands = mp.solutions.hands
hands = mphands.Hands()
mpdraw = mp.solutions.drawing_utils
ptime = 0
ctime = 0
while True:
success, img = cap.read()
imgrgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
results = hands.process(imgrgb)
# print(results.multi_hand_landmarks)
if results.multi_hand_landmarks:
for handlms in results.multi_hand_landmarks:
mpdraw.draw_landmarks(img, handlms, mphands.HAND_CONNECTIONS)
ctime = t.time()
fps = 1 / (ctime - ptime)
ptime = ctime
# Move cv2.putText here to ensure it's drawn on the image
cv2.putText(img, f"FPS: {int(fps)}", (10, 70), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 255), 2)
cv2.imshow("image", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()