MCPcopy Create free account
hub / github.com/Francis-Rings/StableAnimator / draw_bodypose

Function draw_bodypose

DWPose/skeleton_extraction.py:16–59  ·  view source on GitHub ↗
(canvas, candidate, subset, score)

Source from the content-addressed store, hash-verified

14 return [int(c * alpha) for c in color]
15
16def draw_bodypose(canvas, candidate, subset, score):
17 H, W, C = canvas.shape
18 candidate = np.array(candidate)
19 subset = np.array(subset)
20
21 stickwidth = 4
22
23 limbSeq = [[2, 3], [2, 6], [3, 4], [4, 5], [6, 7], [7, 8], [2, 9], [9, 10], \
24 [10, 11], [2, 12], [12, 13], [13, 14], [2, 1], [1, 15], [15, 17], \
25 [1, 16], [16, 18], [3, 17], [6, 18]]
26
27 colors = [[255, 0, 0], [255, 85, 0], [255, 170, 0], [255, 255, 0], [170, 255, 0], [85, 255, 0], [0, 255, 0], \
28 [0, 255, 85], [0, 255, 170], [0, 255, 255], [0, 170, 255], [0, 85, 255], [0, 0, 255], [85, 0, 255], \
29 [170, 0, 255], [255, 0, 255], [255, 0, 170], [255, 0, 85]]
30
31 for i in range(17):
32 for n in range(len(subset)):
33 index = subset[n][np.array(limbSeq[i]) - 1]
34 conf = score[n][np.array(limbSeq[i]) - 1]
35 if conf[0] < 0.3 or conf[1] < 0.3:
36 continue
37 Y = candidate[index.astype(int), 0] * float(W)
38 X = candidate[index.astype(int), 1] * float(H)
39 mX = np.mean(X)
40 mY = np.mean(Y)
41 length = ((X[0] - X[1]) ** 2 + (Y[0] - Y[1]) ** 2) ** 0.5
42 angle = math.degrees(math.atan2(X[0] - X[1], Y[0] - Y[1]))
43 polygon = cv2.ellipse2Poly((int(mY), int(mX)), (int(length / 2), stickwidth), int(angle), 0, 360, 1)
44 cv2.fillConvexPoly(canvas, polygon, alpha_blend_color(colors[i], conf[0] * conf[1]))
45
46 canvas = (canvas * 0.6).astype(np.uint8)
47
48 for i in range(18):
49 for n in range(len(subset)):
50 index = int(subset[n][i])
51 if index == -1:
52 continue
53 x, y = candidate[index][0:2]
54 conf = score[n][i]
55 x = int(x * W)
56 y = int(y * H)
57 cv2.circle(canvas, (int(x), int(y)), 4, alpha_blend_color(colors[i], conf), thickness=-1)
58
59 return canvas
60
61def draw_handpose(canvas, all_hand_peaks, all_hand_scores):
62 H, W, C = canvas.shape

Callers 1

draw_poseFunction · 0.70

Calls 1

alpha_blend_colorFunction · 0.70

Tested by

no test coverage detected