minimal-hand iknet quaternion to

2021-09-01  本文已影响0人  Reyuwei

Add this function to https://github.com/CalciferZh/minimal-hand/blob/master/hand_mesh.py
Inspired by https://github.com/CalciferZh/minimal-hand/issues/80

@staticmethod
def convert_iknet_pose(ik_quat):
    ### ik_quat: (21, 4) IKNET output
    ### ret_axangle: (16, 3) MANO pose axis-angle, not exactly the same, but quite similar        
    mat = []
    for j in range(MANOHandJoints.n_joints):
        mat.append(transforms3d.quaternions.quat2mat(ik_quat[j]))
    mat = np.stack(mat, 0)
    
    result_axangle = [None] * MANOHandJoints.n_joints
    result_mat = [None] * MANOHandJoints.n_joints
    for j in range(MANOHandJoints.n_joints):
        parent = MANOHandJoints.parents[j]
        if parent is not None:
            matJ = mat[j]
            matP = mat[parent]
            rel_mat = np.linalg.inv(matP) @ matJ
            axis, ang = transforms3d.axangles.mat2axangle(rel_mat)
            result_axangle[parent] = axis*ang
            result_mat[parent] = rel_mat
    axis, ang = transforms3d.axangles.mat2axangle(mat[0])
    result_axangle[0] = axis*ang
    result_axangle = np.stack(result_axangle[:16])
    return result_axangle

Compare

上一篇下一篇

猜你喜欢

热点阅读