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