File size: 990 Bytes
8478e62
 
 
 
 
00cde0b
8478e62
 
 
 
 
 
 
00cde0b
 
8478e62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import mediapipe as mp

import cv2
from utils import read_n_resize

def mp_hand_pose_detect_fn(image, min_detect_conf=0.5):
    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=min_detect_conf
    ) 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)