Skip to content

Commit c55bfc4

Browse files
authored
Merge pull request #483 from tensorlayer/mpii-docs
add docs, draw head bbox and improve circle - MPII visualization
2 parents d7a59c6 + d9e384a commit c55bfc4

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

tensorlayer/visualize.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ def draw_mpii_people_to_image(image, peoples, save_name='image.png'):
231231
-----------
232232
image : numpy.array
233233
The RGB image [height, width, channel].
234-
people :
234+
people : list of dict
235+
The people(s) annotation in MPII format, see ``tl.files.load_mpii_pose_dataset``.
235236
save_name : None or str
236237
The name of image file (i.e. image.png), if None, not to save image.
237238
@@ -257,25 +258,19 @@ def draw_mpii_people_to_image(image, peoples, save_name='image.png'):
257258
# import skimage
258259
# don't change the original image, and avoid error https://stackoverflow.com/questions/30249053/python-opencv-drawing-errors-after-manipulating-array-with-numpy
259260
image = image.copy()
260-
radius = int(image.shape[1] / 500) + 1
261261

262262
imh, imw = image.shape[0:2]
263263
thick = int((imh + imw) // 430)
264+
# radius = int(image.shape[1] / 500) + 1
265+
radius = int(thick * 1.5)
264266

265267
if image.max() < 1:
266268
image = image * 255
267269

268270
for people in peoples:
271+
### Pose Keyponts
269272
joint_pos = people['joint_pos']
270-
## draw circles
271-
for pos in joint_pos.items():
272-
_, pos_loc = pos # pos_id, pos_loc
273-
pos_loc = (int(pos_loc[0]), int(pos_loc[1]))
274-
cv2.circle(image, center=pos_loc, radius=radius, color=(0, 255, 0), thickness=-1)
275-
# rr, cc = skimage.draw.circle(int(pos_loc[1]), int(pos_loc[0]), radius)
276-
# image[rr, cc] = [0, 255, 0]
277-
278-
## draw sketch
273+
# draw sketch
279274
# joint id (0 - r ankle, 1 - r knee, 2 - r hip, 3 - l hip, 4 - l knee,
280275
# 5 - l ankle, 6 - pelvis, 7 - thorax, 8 - upper neck,
281276
# 9 - head top, 10 - r wrist, 11 - r elbow, 12 - r shoulder,
@@ -321,6 +316,23 @@ def draw_mpii_people_to_image(image, peoples, save_name='image.png'):
321316
thick)
322317
# rr, cc, val = skimage.draw.line_aa(int(joint_pos[start][1]), int(joint_pos[start][0]), int(joint_pos[end][1]), int(joint_pos[end][0]))
323318
# image[rr, cc] = line[1]
319+
# draw circles
320+
for pos in joint_pos.items():
321+
_, pos_loc = pos # pos_id, pos_loc
322+
pos_loc = (int(pos_loc[0]), int(pos_loc[1]))
323+
cv2.circle(image, center=pos_loc, radius=radius, color=(200, 200, 200), thickness=-1)
324+
# rr, cc = skimage.draw.circle(int(pos_loc[1]), int(pos_loc[0]), radius)
325+
# image[rr, cc] = [0, 255, 0]
326+
327+
### Head
328+
head_rect = people['head_rect']
329+
if head_rect: # if head exists
330+
cv2.rectangle(
331+
image,
332+
(int(head_rect[0]), int(head_rect[1])),
333+
(int(head_rect[2]), int(head_rect[3])), # up-left and botton-right
334+
[0, 180, 0],
335+
thick)
324336

325337
if save_name is not None:
326338
# cv2.imwrite(save_name, image)

0 commit comments

Comments
 (0)