NetEase-GameAI / Face2FaceRHO

The Official PyTorch Implementation for Face2Face^ρ (ECCV2022)
BSD 3-Clause "New" or "Revised" License
212 stars 35 forks source link

headpose参数中的二维偏移量和缩放因子如何得到? #26

Open wong00 opened 1 year ago

wong00 commented 1 year ago

在本项目中,将DECA的输出的headpose经过预定义的scale_transform等参数进行变换,从而对应于face2face的输入;

那么当我使用3DDFA模型时,输出得到的偏移量和缩放因子该如何变换,才能对应face2face的输入呢?

wong00 commented 1 year ago

3DDFA得到偏移量和缩放因子的代码如下:

def P2sRt(P):
    """ decompositing camera matrix P.
    Args:
        P: (3, 4). Affine Camera Matrix.
    Returns:
        s: scale factor.
        R: (3, 3). rotation matrix.
        t2d: (2,). 2d translation.
    """
    t3d = P[:, 3]
    R1 = P[0:1, :3]
    R2 = P[1:2, :3]
    s = (np.linalg.norm(R1) + np.linalg.norm(R2)) / 2.0
    r1 = R1 / np.linalg.norm(R1)
    r2 = R2 / np.linalg.norm(R2)
    r3 = np.cross(r1, r2)
    R = np.concatenate((r1, r2, r3), 0)
    return s, R, t3d