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

Function draw_handpose_new

tools/preprocess/human_visualization.py:97–175  ·  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, stickwidth_type="v2", hand_score_th=0.6)

Source from the content-addressed store, hash-verified

95
96
97def draw_handpose_new(canvas, keypoints, stickwidth_type="v2", hand_score_th=0.6):
98 """
99 Draw keypoints and connections representing hand pose on a given canvas.
100
101 Args:
102 canvas (np.ndarray): A 3D numpy array representing the canvas (image) on which to draw the hand pose.
103 keypoints (List[Keypoint]| None): A list of Keypoint objects representing the hand keypoints to be drawn
104 or None if no keypoints are present.
105
106 Returns:
107 np.ndarray: A 3D numpy array representing the modified canvas with the drawn hand pose.
108
109 Note:
110 The function expects the x and y coordinates of the keypoints to be normalized between 0 and 1.
111 """
112 eps = 0.01
113
114 H, W, C = canvas.shape
115 if stickwidth_type == "v1":
116 stickwidth = max(int(min(H, W) / 200), 1)
117 elif stickwidth_type == "v2":
118 stickwidth = max(max(int(min(H, W) / 200) - 1, 1) // 2, 1)
119
120 edges = [
121 [0, 1],
122 [1, 2],
123 [2, 3],
124 [3, 4],
125 [0, 5],
126 [5, 6],
127 [6, 7],
128 [7, 8],
129 [0, 9],
130 [9, 10],
131 [10, 11],
132 [11, 12],
133 [0, 13],
134 [13, 14],
135 [14, 15],
136 [15, 16],
137 [0, 17],
138 [17, 18],
139 [18, 19],
140 [19, 20],
141 ]
142
143 for ie, (e1, e2) in enumerate(edges):
144 k1 = keypoints[e1]
145 k2 = keypoints[e2]
146 if k1 is None or k2 is None:
147 continue
148 if k1[2] < hand_score_th or k2[2] < hand_score_th:
149 continue
150
151 x1 = int(k1[0])
152 y1 = int(k1[1])
153 x2 = int(k2[0])
154 y2 = int(k2[1])

Callers 1

draw_aapose_newFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected