shaohua-pan / RobustCap

Code for our SIGGRAPH ASIA 2023 paper "Fusing Monocular Images and Sparse IMU Signals for Real-time Human Motion Capture".
https://shaohua-pan.github.io/robustcap-page/
MIT License
127 stars 10 forks source link

optimize reprojection error #4

Closed yxyyundanfengqing closed 11 months ago

yxyyundanfengqing commented 1 year ago

if self.use_reproj_opt and c > self.conf_range[0]: p = j2dc[:, 2]#获取置信度

optimize x, y

        ax = (p / j[:, 2].pow(2)).sum() + self.smooth
        bx = (p * (- j[:, 0] / j[:, 2].pow(2) + j2dc[:, 0] / j[:, 2])).sum()
        ay = (p / j[:, 2].pow(2)).sum() + self.smooth
        by = (p * (- j[:, 1] / j[:, 2].pow(2) + j2dc[:, 1] / j[:, 2])).sum()
        d_tran = torch.tensor([bx / ax, by / ay, 0]).to(device)
        tran = tran + d_tran
        # optimize z
        j = j + d_tran#这里已经更新了bx和by
        az = (p * (j[:, 0].pow(2) + j[:, 1].pow(2)) / j[:, 2].pow(4)).sum() + self.smooth
        bz = (p * ((j[:, 0] / j[:, 2] - j2dc[:, 0]) * j[:, 0] / j[:, 2].pow(2) + (
                j[:, 1] / j[:, 2] - j2dc[:, 1]) * j[:, 1] / j[:, 2].pow(2))).sum()
        d_tran = torch.tensor([0, 0, bz / az]).to(device)  

请问在上述代码中az和bz的计算依据是什么

image

我的式子是正确的嘛,我无法推导出az和bz

shaohua-pan commented 1 year ago

重投影优化直接参考smplify_runner吧

yxyyundanfengqing commented 1 year ago

@shaohua-pan ,你好,这是我在smplify_runner中找到的相关代码,我知道他是相机坐标系下的点左乘相机内参矩阵得到图片上的点坐标,但我仍然不知道ax,bx,ay,by,az,bz的计算依据,请问您能给出数学推导嘛? projected_joints = model_joints / model_joints[..., 2:]#projected_joints = model_joints / model_joints[..., 2:]:这一行代码将3D关键点的x和y坐标分别除以z坐标,以实现透视投影。这是将3D点投影到2D图像平面的基本操作。在这个步骤之后,projected_joints包含了归一化的2D关键点坐标。 projected_joints = cam_k.matmul(projected_joints.unsqueeze(-1)).squeeze(-1)[..., :2]#2302,33,3 2302,33,3,1 2302,33,3,1 2302,33,3 2302,33,2

torch.Size([2302, 6, 3, 3])

imu_ori_loss = (imu_ori_weight ** 2) * ((art.math.rotation_matrix_to_axis_angle(imu_ori).reshape(body_pose.shape[0], -1) -
                                         art.math.rotation_matrix_to_axis_angle(ori).reshape(body_pose.shape[0], -1)) ** 2).sum(dim=-1)
#在这段代码中,imu_ori_loss计算了IMU方向损失。IMU方向损失表示IMU方向数据(imu_ori)与3D关键点方向(ori)之间的差异。这个损失项可以帮助约束3D姿态估计,使其更符合IMU方向数据。
# Weighted robust reprojection error
reprojection_error = gmof(projected_joints - joints_2d, sigma)
# joints_invalid = torch.where(joints_conf.mean(dim=1)<0.3)
# joints_conf[joints_conf < 0.3] = 0.0
reprojection_loss = (joints_conf ** 2) * reprojection_error.sum(dim=-1)#计算重投影损失2302,33
shaohua-pan commented 12 months ago

smplify_runner,这个就是直接优化求解的pose和tran,考虑了2d重投影以及一些人体先验的约束。ax,bx,ay,by,az,bz这段代码没有用

yxyyundanfengqing commented 11 months ago

谢谢