-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgestureRecognition.py
More file actions
42 lines (31 loc) · 1.14 KB
/
gestureRecognition.py
File metadata and controls
42 lines (31 loc) · 1.14 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
import cv2
import mediapipe as mp
# Initialize MediaPipe Hands
mp_hands = mp.solutions.hands
hands = mp_hands.Hands(static_image_mode=False,
max_num_hands=2,
min_detection_confidence=0.7)
mp_drawing = mp.solutions.drawing_utils
# Start video capture from the webcam
cap = cv2.VideoCapture(0)
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# Flip the frame horizontally for a selfie-view display
frame = cv2.flip(frame, 1)
# Convert the frame to RGB
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Process the frame and detect hands
results = hands.process(rgb_frame)
# Draw the hand annotations on the frame
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
# Display the resulting frame
cv2.imshow('Gesture Recognition', frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release the capture and close any open windows
cap.release()
cv2.destroyAllWindows()