PyTorch实现OpenCV鱼眼相机投影存在微小偏差问题排查
鱼眼相机PyTorch投影实现与OpenCV偏差问题
拥有3台已标定的鱼眼相机和1台普通相机,需在PyTorch中实现OpenCV的projectPoints()与fisheye.projectPoints()函数,以支持反向传播操作。目前已完成大部分实现,但鱼眼相机的投影结果与OpenCV输出存在微小偏差,投影点呈现类似拉伸的差异。已尝试重写代码、检查参数顺序、切换32/64位精度等操作,问题仍未解决,现寻求问题原因及解决方法。
现有代码实现
def distort(self, points): x = points[:, 0] y = points[:, 1] r = torch.sqrt(torch.square(x) + torch.square(y)) theta = torch.atan(r) theta2 = theta**2 theta4 = theta2**2 theta6 = theta2**3 theta8 = theta4**2 D_mx = self.get_D() theta_d = theta * (1 + (D_mx[0].item() * theta2) + (D_mx[1].item() * theta4) + (D_mx[2].item() * theta6) + (D_mx[3].item() * theta8) ) x_dist = (theta_d / r) * x y_dist = (theta_d / r) * y dist_pts = torch.stack((x_dist,y_dist), dim=1) return dist_pts def project_world(self, points, distort=None): utils.check_tensor(points, shape=[points.shape[0],3], dtype=torch.double) points = points.view(-1,3,1) camera_points = torch.matmul(self.get_R_mx(), points).view(-1,3) + self.get_T_vec().view(3) return self.project(camera_points, distort=distort) def project(self, points, distort=None): utils.check_tensor(points, shape=[points.shape[0], 3]) points = points[:, :2] / points[:,2:3] if distort is not None: points = self.distort(points) elif self.should_distort: points = self.distort(points) points = points.view(-1, 2, 1) projected = torch.matmul(self.get_K()[:2,:2], points).view(-1, 2) + self.get_K()[:2,2] utils.check_tensor(projected, shape=[projected.shape[0],2]) return projected
内容的提问来源于stack exchange,提问作者pattyhoops
相关产品推荐
相关产品推荐

