From 7f73debfdd904163a1a9e489840cad986c22669f Mon Sep 17 00:00:00 2001 From: ly015 Date: Wed, 2 Mar 2022 11:53:23 +0800 Subject: [PATCH] fix color channel order in visualization functions and docs --- docs/en/tutorials/2_new_dataset.md | 2 +- docs/zh_cn/tutorials/2_new_dataset.md | 2 +- mmpose/core/visualization/image.py | 18 ++++++------------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/docs/en/tutorials/2_new_dataset.md b/docs/en/tutorials/2_new_dataset.md index a4d39110a1..de628b49e1 100644 --- a/docs/en/tutorials/2_new_dataset.md +++ b/docs/en/tutorials/2_new_dataset.md @@ -74,7 +74,7 @@ An example of the dataset config is as follows. 1. `name`: the keypoint name. The keypoint name must be unique. 2. `id`: the keypoint id. -3. `color`: ([R, G, B]) is used for keypoint visualization. +3. `color`: ([B, G, R]) is used for keypoint visualization. 4. `type`: 'upper' or 'lower', will be used in data augmetation. 5. `swap`: indicates the 'swap pair' (also known as 'flip pair'). When applying image horizontal flip, the left part will become the right part. We need to flip the keypoints accordingly. diff --git a/docs/zh_cn/tutorials/2_new_dataset.md b/docs/zh_cn/tutorials/2_new_dataset.md index 3ce3267453..53d43062d2 100644 --- a/docs/zh_cn/tutorials/2_new_dataset.md +++ b/docs/zh_cn/tutorials/2_new_dataset.md @@ -74,7 +74,7 @@ configs/_base_/datasets/custom.py 1. `name`: 代表关键点的名称。一个数据集的每个关键点,名称必须唯一。 2. `id`: 关键点的标识号。 -3. `color`: ([R, G, B]) 用于可视化关键点。 +3. `color`: ([B, G, R]) 用于可视化关键点。 4. `type`: 分为 'upper' 和 'lower' 两种,用于数据增强。 5. `swap`: 表示与当前关键点,“镜像对称”的关键点名称。 diff --git a/mmpose/core/visualization/image.py b/mmpose/core/visualization/image.py index 27f1488421..8acd10bd58 100644 --- a/mmpose/core/visualization/image.py +++ b/mmpose/core/visualization/image.py @@ -143,11 +143,11 @@ def imshow_keypoints(img, for kid, kpt in enumerate(kpts): x_coord, y_coord, kpt_score = int(kpt[0]), int(kpt[1]), kpt[2] if kpt_score > kpt_score_thr: + color = tuple(int(c) for c in pose_kpt_color[kid]) if show_keypoint_weight: img_copy = img.copy() - r, g, b = pose_kpt_color[kid] cv2.circle(img_copy, (int(x_coord), int(y_coord)), - radius, (int(r), int(g), int(b)), -1) + radius, color, -1) transparency = max(0, min(1, kpt_score)) cv2.addWeighted( img_copy, @@ -157,9 +157,8 @@ def imshow_keypoints(img, 0, dst=img) else: - r, g, b = pose_kpt_color[kid] cv2.circle(img, (int(x_coord), int(y_coord)), radius, - (int(r), int(g), int(b)), -1) + color, -1) # draw links if skeleton is not None and pose_link_color is not None: @@ -172,7 +171,7 @@ def imshow_keypoints(img, and pos2[1] > 0 and pos2[1] < img_h and kpts[sk[0], 2] > kpt_score_thr and kpts[sk[1], 2] > kpt_score_thr): - r, g, b = pose_link_color[sk_id] + color = tuple(int(c) for c in pose_link_color[sk_id]) if show_keypoint_weight: img_copy = img.copy() X = (pos1[0], pos2[0]) @@ -187,8 +186,7 @@ def imshow_keypoints(img, (int(mX), int(mY)), (int(length / 2), int(stickwidth)), int(angle), 0, 360, 1) - cv2.fillConvexPoly(img_copy, polygon, - (int(r), int(g), int(b))) + cv2.fillConvexPoly(img_copy, polygon, color) transparency = max( 0, min(1, 0.5 * (kpts[sk[0], 2] + kpts[sk[1], 2]))) cv2.addWeighted( @@ -199,11 +197,7 @@ def imshow_keypoints(img, 0, dst=img) else: - cv2.line( - img, - pos1, - pos2, (int(r), int(g), int(b)), - thickness=thickness) + cv2.line(img, pos1, pos2, color, thickness=thickness) return img