嗨,我目前在流行的 2d 关键点输出之间进行转换,从COCO keypoints
到openpose
。我从xy 坐标coco
的顺序的关键点得到以下关键点顺序x1,y1,c1 ....x17,y17,c17
,并且是被检测关节的置信度得分。我想知道是否有人成功地在和之间映射x,y
C
Coco
openpose
问问题
736 次
1 回答
0
def convert_coco_to_openpose_cords(coco_keypoints_list):
# coco keypoints: [x1,y1,v1,...,xk,yk,vk] (k=17)
# ['Nose', Leye', 'Reye', 'Lear', 'Rear', 'Lsho', 'Rsho', 'Lelb',
# 'Relb', 'Lwri', 'Rwri', 'Lhip', 'Rhip', 'Lkne', 'Rkne', 'Lank', 'Rank']
# openpose keypoints: [y1,...,yk], [x1,...xk] (k=18, with Neck)
# ['Nose', *'Neck'*, 'Rsho', 'Relb', 'Rwri', 'Lsho', 'Lelb', 'Lwri','Rhip',
# 'Rkne', 'Rank', 'Lhip', 'Lkne', 'Lank', 'Leye', 'Reye', 'Lear', 'Rear']
indices = [0, 6, 8, 10, 5, 7, 9, 12, 14, 16, 11, 13, 15, 1, 2, 3, 4]
y_cords = []
x_cords = []
for i in indices:
xi, yi, vi = coco_keypoints_list[i*3:(i+1)*3]
if vi == 0: # not labeled
y_cords.append(MISSING_VALUE)
x_cords.append(MISSING_VALUE)
elif vi == 1: # labeled but not visible
y_cords.append(yi)
x_cords.append(xi)
elif vi == 2: # labeled and visible
y_cords.append(yi)
x_cords.append(xi)
else:
raise ValueError("vi value: {}".format(vi))
# Get 'Neck' keypoint by interpolating between 'Lsho' and 'Rsho' keypoints
l_shoulder_index = 5
r_shoulder_index = 6
l_shoulder_keypoint = coco_keypoints_list[l_shoulder_index*3:(l_shoulder_index+1)*3]
r_shoulder_keypoint = coco_keypoints_list[r_shoulder_index*3:(r_shoulder_index+1)*3]
if l_shoulder_keypoint[2] > 0 and r_shoulder_keypoint[2] > 0:
neck_keypoint_y = int((l_shoulder_keypoint[1]+r_shoulder_keypoint[1])/2.)
neck_keypoint_x = int((l_shoulder_keypoint[0]+r_shoulder_keypoint[0])/2.)
else:
neck_keypoint_y = neck_keypoint_x = MISSING_VALUE
open_pose_neck_index = 1
y_cords.insert(open_pose_neck_index, neck_keypoint_y)
x_cords.insert(open_pose_neck_index, neck_keypoint_x)
return np.concatenate([np.expand_dims(y_cords, -1),
np.expand_dims(x_cords, -1)], axis=1)
于 2019-08-23T06:35:15.960 回答