File size: 842 Bytes
4b78090
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import matplotlib.pyplot as plt
import mediapipe as mp

def plot_hand_landmarks(landmarks, title):
    """
    Plot hand landmarks on a figure.
    
    Parameters:
        landmarks (numpy.ndarray): Array of hand landmarks.
        title (str): Title of the plot.

    Returns:
        matplotlib.figure.Figure: The plotted figure.
    """
    fig, ax = plt.subplots(figsize=(5, 5))
    ax.scatter(landmarks[:, 0], landmarks[:, 1], c='blue', s=20)
    mp_hands = mp.solutions.hands
    for connection in mp_hands.HAND_CONNECTIONS:
        start_idx = connection[0]
        end_idx = connection[1]
        ax.plot([landmarks[start_idx, 0], landmarks[end_idx, 0]],
                [landmarks[start_idx, 1], landmarks[end_idx, 1]], 'r-', linewidth=1)
    ax.invert_yaxis()
    ax.set_title(title, fontsize=12)
    ax.axis('off')
    return fig