-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
20 lines (18 loc) · 672 Bytes
/
Copy pathtest.py
File metadata and controls
20 lines (18 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import cv2
import mediapipe as mp
mp_hands = mp.solutions.hands.Hands()
cap = cv2.VideoCapture(0)
while True:
ok, frame = cap.read()
if not ok: break
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
out = mp_hands.process(rgb)
if out.multi_hand_landmarks:
for hand in out.multi_hand_landmarks:
h,w,_ = frame.shape
xs = [lm.x * w for lm in hand.landmark]
ys = [lm.y * h for lm in hand.landmark]
x1,y1,x2,y2 = int(min(xs)), int(min(ys)), int(max(xs)), int(max(ys))
cv2.rectangle(frame, (x1,y1), (x2,y2), (0,255,0), 2)
cv2.imshow("hand bbox", frame)
if cv2.waitKey(1) == 27: break