关键点可可和开放姿势之间的转换?

时间:2019-05-16 15:57:19

标签: computer-vision pose-estimation openpose

您好,我目前在介于流行的2d关键点输出(从openpose到COCO关键点)之间进行转换方面感到困惑。有没有办法重新排序“开放姿势”和“ COCO”之间的关键点?

1 个答案:

答案 0 :(得分: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)