xinsir commited on
Commit
3fc3b67
1 Parent(s): a6ff772

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +81 -0
README.md CHANGED
@@ -51,6 +51,87 @@ tags:
51
  ![images8](./000048_scribble_concat.webp)
52
  ![images9](./000083_scribble_concat.webp)
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  ## How to Get Started with the Model
55
 
56
  Use the code below to get started with the model.
 
51
  ![images8](./000048_scribble_concat.webp)
52
  ![images9](./000083_scribble_concat.webp)
53
 
54
+ ## Replace the default draw pose function to get better result
55
+ thanks feiyuuu for report the problem. When using the default pose line the performance may be unstable, this is because the pose label use more thick line in training to have a better look.
56
+ This difference can be fix by using the following method:
57
+
58
+ Find the util.py in controlnet_aux python package, usually the path is like: /your anaconda3 path/envs/your env name/lib/python3.8/site-packages/controlnet_aux/open_pose/util.py
59
+ Replace the draw_bodypose function with the following code:
60
+ ```python
61
+ def draw_bodypose(canvas: np.ndarray, keypoints: List[Keypoint]) -> np.ndarray:
62
+ """
63
+ Draw keypoints and limbs representing body pose on a given canvas.
64
+
65
+ Args:
66
+ canvas (np.ndarray): A 3D numpy array representing the canvas (image) on which to draw the body pose.
67
+ keypoints (List[Keypoint]): A list of Keypoint objects representing the body keypoints to be drawn.
68
+
69
+ Returns:
70
+ np.ndarray: A 3D numpy array representing the modified canvas with the drawn body pose.
71
+
72
+ Note:
73
+ The function expects the x and y coordinates of the keypoints to be normalized between 0 and 1.
74
+ """
75
+ H, W, C = canvas.shape
76
+
77
+
78
+ if max(W, H) < 500:
79
+ ratio = 1.0
80
+ elif max(W, H) >= 500 and max(W, H) < 1000:
81
+ ratio = 2.0
82
+ elif max(W, H) >= 1000 and max(W, H) < 2000:
83
+ ratio = 3.0
84
+ elif max(W, H) >= 2000 and max(W, H) < 3000:
85
+ ratio = 4.0
86
+ elif max(W, H) >= 3000 and max(W, H) < 4000:
87
+ ratio = 5.0
88
+ elif max(W, H) >= 4000 and max(W, H) < 5000:
89
+ ratio = 6.0
90
+ else:
91
+ ratio = 7.0
92
+
93
+ stickwidth = 4
94
+
95
+ limbSeq = [
96
+ [2, 3], [2, 6], [3, 4], [4, 5],
97
+ [6, 7], [7, 8], [2, 9], [9, 10],
98
+ [10, 11], [2, 12], [12, 13], [13, 14],
99
+ [2, 1], [1, 15], [15, 17], [1, 16],
100
+ [16, 18],
101
+ ]
102
+
103
+ colors = [[255, 0, 0], [255, 85, 0], [255, 170, 0], [255, 255, 0], [170, 255, 0], [85, 255, 0], [0, 255, 0], \
104
+ [0, 255, 85], [0, 255, 170], [0, 255, 255], [0, 170, 255], [0, 85, 255], [0, 0, 255], [85, 0, 255], \
105
+ [170, 0, 255], [255, 0, 255], [255, 0, 170], [255, 0, 85]]
106
+
107
+ for (k1_index, k2_index), color in zip(limbSeq, colors):
108
+ keypoint1 = keypoints[k1_index - 1]
109
+ keypoint2 = keypoints[k2_index - 1]
110
+
111
+ if keypoint1 is None or keypoint2 is None:
112
+ continue
113
+
114
+ Y = np.array([keypoint1.x, keypoint2.x]) * float(W)
115
+ X = np.array([keypoint1.y, keypoint2.y]) * float(H)
116
+ mX = np.mean(X)
117
+ mY = np.mean(Y)
118
+ length = ((X[0] - X[1]) ** 2 + (Y[0] - Y[1]) ** 2) ** 0.5
119
+ angle = math.degrees(math.atan2(X[0] - X[1], Y[0] - Y[1]))
120
+ polygon = cv2.ellipse2Poly((int(mY), int(mX)), (int(length / 2), int(stickwidth * ratio)), int(angle), 0, 360, 1)
121
+ cv2.fillConvexPoly(canvas, polygon, [int(float(c) * 0.6) for c in color])
122
+
123
+ for keypoint, color in zip(keypoints, colors):
124
+ if keypoint is None:
125
+ continue
126
+
127
+ x, y = keypoint.x, keypoint.y
128
+ x = int(x * W)
129
+ y = int(y * H)
130
+ cv2.circle(canvas, (int(x), int(y)), int(4 * ratio), color, thickness=-1)
131
+
132
+ return canvas
133
+ ```
134
+
135
  ## How to Get Started with the Model
136
 
137
  Use the code below to get started with the model.