Spaces:
Runtime error
Runtime error
| import mediapipe as mp | |
| import cv2 | |
| from utils import read_n_resize | |
| def mp_hand_pose_detect_fn(image): | |
| mp_drawing = mp.solutions.drawing_utils | |
| mp_drawing_styles = mp.solutions.drawing_styles | |
| mp_hands = mp.solutions.hands | |
| with mp_hands.Hands( | |
| static_image_mode=True, | |
| max_num_hands=5, | |
| min_detection_confidence=0.5 | |
| ) as hands: | |
| image = cv2.flip(read_n_resize(image, read=False), 1) | |
| results = hands.process(image) | |
| image_height, image_width, _ = image.shape | |
| annotated_image = image.copy() | |
| for hand_landmarks in results.multi_hand_landmarks: | |
| mp_drawing.draw_landmarks( | |
| annotated_image, | |
| hand_landmarks, | |
| mp_hands.HAND_CONNECTIONS, | |
| mp_drawing_styles.get_default_hand_landmarks_style(), | |
| mp_drawing_styles.get_default_hand_connections_style()) | |
| return cv2.flip(annotated_image, 1) | |