tgoop.com/CodeProgrammer/2378
Last Update:
✋ Hand gesture recognitionimport cv2
import mediapipe as mp
# Initialize MediaPipe Hands module
mp_hands = mp.solutions.hands
hands = mp_hands.Hands()
# Initialize MediaPipe Drawing module for drawing landmarks
mp_drawing = mp.solutions.drawing_utils
# Open a video capture object (0 for the default camera)
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
continue
# Convert the frame to RGB format
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Process the frame to detect hands
results = hands.process(frame_rgb)
# Check if hands are detected
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
# Draw landmarks on the frame
mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
# Display the frame with hand landmarks
cv2.imshow('Hand Recognition', frame)
# Exit when 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release the video capture object and close the OpenCV windows
cap.release()
cv2.destroyAllWindows()
https://www.tgoop.com/CodeProgrammer
Please more reaction with our posts
BY Python | Machine Learning | Coding | R

Share with your friend now:
tgoop.com/CodeProgrammer/2378