From 6e5312f0b681b518d750b0ce61c2465a835452ff Mon Sep 17 00:00:00 2001 From: zsdonghao Date: Tue, 10 Apr 2018 22:16:26 +0100 Subject: [PATCH 1/3] add docs - MPII visualization --- tensorlayer/visualize.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tensorlayer/visualize.py b/tensorlayer/visualize.py index 42a388a8b..f431947e5 100644 --- a/tensorlayer/visualize.py +++ b/tensorlayer/visualize.py @@ -231,7 +231,8 @@ def draw_mpii_people_to_image(image, peoples, save_name='image.png'): ----------- image : numpy.array The RGB image [height, width, channel]. - people : + people : list of dict + The people(s) annotation in MPII format, see ``tl.files.load_mpii_pose_dataset``. save_name : None or str The name of image file (i.e. image.png), if None, not to save image. From 81bdc1491e3f5ea912026ce6373cc07d7b970af5 Mon Sep 17 00:00:00 2001 From: zsdonghao Date: Tue, 10 Apr 2018 22:41:09 +0100 Subject: [PATCH 2/3] mpii visulization - draw head bbox --- tensorlayer/visualize.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tensorlayer/visualize.py b/tensorlayer/visualize.py index f431947e5..7ebf54143 100644 --- a/tensorlayer/visualize.py +++ b/tensorlayer/visualize.py @@ -267,8 +267,9 @@ def draw_mpii_people_to_image(image, peoples, save_name='image.png'): image = image * 255 for people in peoples: + ### Pose Keyponts joint_pos = people['joint_pos'] - ## draw circles + # draw circles for pos in joint_pos.items(): _, pos_loc = pos # pos_id, pos_loc pos_loc = (int(pos_loc[0]), int(pos_loc[1])) @@ -276,7 +277,7 @@ def draw_mpii_people_to_image(image, peoples, save_name='image.png'): # rr, cc = skimage.draw.circle(int(pos_loc[1]), int(pos_loc[0]), radius) # image[rr, cc] = [0, 255, 0] - ## draw sketch + # draw sketch # joint id (0 - r ankle, 1 - r knee, 2 - r hip, 3 - l hip, 4 - l knee, # 5 - l ankle, 6 - pelvis, 7 - thorax, 8 - upper neck, # 9 - head top, 10 - r wrist, 11 - r elbow, 12 - r shoulder, @@ -322,6 +323,15 @@ def draw_mpii_people_to_image(image, peoples, save_name='image.png'): thick) # 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])) # image[rr, cc] = line[1] + ### Head + head_rect = people['head_rect'] + if head_rect: # if head exists + cv2.rectangle( + image, + (int(head_rect[0]), int(head_rect[1])), + (int(head_rect[2]), int(head_rect[3])), # up-left and botton-right + [0, 180, 0], + thick) if save_name is not None: # cv2.imwrite(save_name, image) From d9e384a9be681ee80aaa8f84f7e132d720c6b26b Mon Sep 17 00:00:00 2001 From: zsdonghao Date: Tue, 10 Apr 2018 22:47:22 +0100 Subject: [PATCH 3/3] improve visualization --- tensorlayer/visualize.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tensorlayer/visualize.py b/tensorlayer/visualize.py index 7ebf54143..74df4d9b9 100644 --- a/tensorlayer/visualize.py +++ b/tensorlayer/visualize.py @@ -258,10 +258,11 @@ def draw_mpii_people_to_image(image, peoples, save_name='image.png'): # import skimage # don't change the original image, and avoid error https://stackoverflow.com/questions/30249053/python-opencv-drawing-errors-after-manipulating-array-with-numpy image = image.copy() - radius = int(image.shape[1] / 500) + 1 imh, imw = image.shape[0:2] thick = int((imh + imw) // 430) + # radius = int(image.shape[1] / 500) + 1 + radius = int(thick * 1.5) if image.max() < 1: image = image * 255 @@ -269,14 +270,6 @@ def draw_mpii_people_to_image(image, peoples, save_name='image.png'): for people in peoples: ### Pose Keyponts joint_pos = people['joint_pos'] - # draw circles - for pos in joint_pos.items(): - _, pos_loc = pos # pos_id, pos_loc - pos_loc = (int(pos_loc[0]), int(pos_loc[1])) - cv2.circle(image, center=pos_loc, radius=radius, color=(0, 255, 0), thickness=-1) - # rr, cc = skimage.draw.circle(int(pos_loc[1]), int(pos_loc[0]), radius) - # image[rr, cc] = [0, 255, 0] - # draw sketch # joint id (0 - r ankle, 1 - r knee, 2 - r hip, 3 - l hip, 4 - l knee, # 5 - l ankle, 6 - pelvis, 7 - thorax, 8 - upper neck, @@ -323,6 +316,14 @@ def draw_mpii_people_to_image(image, peoples, save_name='image.png'): thick) # 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])) # image[rr, cc] = line[1] + # draw circles + for pos in joint_pos.items(): + _, pos_loc = pos # pos_id, pos_loc + pos_loc = (int(pos_loc[0]), int(pos_loc[1])) + cv2.circle(image, center=pos_loc, radius=radius, color=(200, 200, 200), thickness=-1) + # rr, cc = skimage.draw.circle(int(pos_loc[1]), int(pos_loc[0]), radius) + # image[rr, cc] = [0, 255, 0] + ### Head head_rect = people['head_rect'] if head_rect: # if head exists