计算 N*4*4 位姿形状的逆变换,在N*3*4位姿后补充 [0,0,0,1]

针对 [N,4,4] shape 的 poses,函数 ComputeInversePoses 返回 相同 shape,但是每个 pose 都是前面的 逆 pose。

针对 [N,3,4] shape 的 poses,函数 AddIdentityToPoses 返回 在每个 [3,4] pose下加上 [0,0,0,1] 后的pose,返回的 shape [N,4,4]

def ComputeInversePoses(poses):
    if isinstance(poses, torch.Tensor):
        # Convert torch tensor to numpy array
        poses = poses.numpy()

    # Check if poses is a numpy array
    if not isinstance(poses, np.ndarray):
        raise ValueError("Input poses must be a numpy array")

    # Check if poses is 3-dimensional
    if len(poses.shape) != 3 or poses.shape[1:] != (4, 4):
        raise ValueError("Input poses must be a 3-dimensional array with shape (N, 4, 4)")

    # Create an array to store the inverse poses
    inverse_poses = np.zeros_like(poses)

    # Compute the inverse for each 4x4 matrix
    for i in range(poses.shape[0]):
        inverse_poses[i] = np.linalg.inv(poses[i])

    return inverse_poses.astype(np.float32)


def AddIdentityToPoses(poses):
    # Check if poses is a torch tensor
    if isinstance(poses, torch.Tensor):
        # Convert torch tensor to numpy array
        poses = poses.numpy()

    # Check if poses is 3-dimensional
    if len(poses.shape) != 3 or poses.shape[2] != 4:
        raise ValueError("Input poses must be a 3-dimensional array with shape (N, 3, 4)")

    # Create poses_with_identity array
    poses_with_identity = np.zeros((poses.shape[0], 4, 4), dtype=np.float32)
    poses_with_identity[:, :3, :4] = poses
    poses_with_identity[:, 3, :] = [0, 0, 0, 1]

    return poses_with_identity.astype(np.float32)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

培之

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值