MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / draw_handpose

Function draw_handpose

tools/preprocess/human_visualization.py:19–94  ·  view source on GitHub ↗

Draw keypoints and connections representing hand pose on a given canvas. Args: canvas (np.ndarray): A 3D numpy array representing the canvas (image) on which to draw the hand pose. keypoints (List[Keypoint]| None): A list of Keypoint objects representing the hand keypoints

(canvas, keypoints, hand_score_th=0.6)

Source from the content-addressed store, hash-verified

17
18
19def draw_handpose(canvas, keypoints, hand_score_th=0.6):
20 """
21 Draw keypoints and connections representing hand pose on a given canvas.
22
23 Args:
24 canvas (np.ndarray): A 3D numpy array representing the canvas (image) on which to draw the hand pose.
25 keypoints (List[Keypoint]| None): A list of Keypoint objects representing the hand keypoints to be drawn
26 or None if no keypoints are present.
27
28 Returns:
29 np.ndarray: A 3D numpy array representing the modified canvas with the drawn hand pose.
30
31 Note:
32 The function expects the x and y coordinates of the keypoints to be normalized between 0 and 1.
33 """
34 eps = 0.01
35
36 H, W, C = canvas.shape
37 stickwidth = max(int(min(H, W) / 200), 1)
38
39 edges = [
40 [0, 1],
41 [1, 2],
42 [2, 3],
43 [3, 4],
44 [0, 5],
45 [5, 6],
46 [6, 7],
47 [7, 8],
48 [0, 9],
49 [9, 10],
50 [10, 11],
51 [11, 12],
52 [0, 13],
53 [13, 14],
54 [14, 15],
55 [15, 16],
56 [0, 17],
57 [17, 18],
58 [18, 19],
59 [19, 20],
60 ]
61
62 for ie, (e1, e2) in enumerate(edges):
63 k1 = keypoints[e1]
64 k2 = keypoints[e2]
65 if k1 is None or k2 is None:
66 continue
67 if k1[2] < hand_score_th or k2[2] < hand_score_th:
68 continue
69
70 x1 = int(k1[0])
71 y1 = int(k1[1])
72 x2 = int(k2[0])
73 y2 = int(k2[1])
74 if x1 > eps and y1 > eps and x2 > eps and y2 > eps:
75 cv2.line(
76 canvas,

Callers 3

draw_MFunction · 0.85
draw_noseFunction · 0.85
draw_aaposeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected