-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhands.py
More file actions
40 lines (30 loc) · 927 Bytes
/
Copy pathhands.py
File metadata and controls
40 lines (30 loc) · 927 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
35
36
37
38
39
40
import cv2
import mediapipe as mp
# Initialize Mediapipe
mp_hands = mp.solutions.hands
mp_draw = mp.solutions.drawing_utils
# Hands model (detects 2 hands max)
hands = mp_hands.Hands(max_num_hands=2, min_detection_confidence=0.7)
# Open webcam
cap = cv2.VideoCapture(0)
while cap.isOpened():
success, frame = cap.read()
if not success:
break
# Convert BGR to RGB
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Process the frame
results = hands.process(rgb_frame)
# Draw hand landmarks
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_draw.draw_landmarks(
frame, hand_landmarks, mp_hands.HAND_CONNECTIONS
)
# Show the frame
cv2.imshow("Hand Gesture Drawing", frame)
# Exit on 'q'
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()