[Question] Question about tiled camera intrinsics #2825
Replies: 2 comments
-
Thank you for posting this question. I'll move the post to our Discussions section for follow up. Here is a summary of considerations that may help you debug your issue. The discrepancy in projecting a bouncing ball's 3D position to the correct pixel coordinates in Isaac Sim's tiled camera setup likely stems from unaccounted lens distortion and intrinsic parameter calibration issues. Key Issues
Possible Solution Workflow1. Verify Intrinsic MatrixUse the corrected intrinsic matrix formula to avoid aperture bugs: # Corrected K matrix calculation
fx = (width * focal_length) / horizontal_aperture
fy = (height * focal_length) / vertical_aperture # Critical fix
cx = width / 2
cy = height / 2
K = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]]) 2. Apply Distortion CorrectionIf your camera uses non-pinhole optics, add distortion parameters to the projection:3 from omni.isaac.lab.utils.math import project_points
# points_3d: (N, 3) in camera frame; K: (3, 3)
points_2d = project_points(points_3d, K, distortion_params) # distortion_params from calibration 3. Transform Points to Camera FrameEnsure 3D points are in the camera's optical frame:4 # Convert world points to camera frame
points_camera = transform_points(points_world, camera.data.pos_w, camera.data.quat_w_ros) 4. Use Built-in Projection APIsIsaac Sim's # Project world points to 2D
uv_points = camera.get_image_coords_from_world_points(points_world) Footnotes
|
Beta Was this translation helpful? Give feedback.
-
Hi, I have checked my code but unfortunately I fould all of your solution could not help. :<
Besides, let me furthur explain my undistortion method. I assume this is a distortion in camera sensor, so I calibrated this sensor and got K and D. Then I used K and D to undistort the rendered image and got the undistorted image gray_np_distorted. gray_np_distorted = cv2.undistort(
src=gray_np,
cameraMatrix=np.array(
cfg.my_cam_cfg.calib_intrinsic_matrix
).reshape(3, 3),
distCoeffs=np.array(cfg.my_cam_cfg.calib_distortion_coefficients),
) Then I directly project the ball pos(camera frame) into the image plane using K. I reckon this should be right but it seems that the projection ball does not match the image ball all the time def project_points_to_camera(
self,
ball_pos: torch.Tensor, # [B, 3] 世界坐标系中的点
robot_pos: torch.Tensor, # [B, 3] 相机父坐标系位置
robot_quat: torch.Tensor, # [B, 4] 相机父坐标系四元数
ball_radius: torch.Tensor,
return_normalized: bool = True, # 是否返回归一化坐标
) -> Tuple[torch.Tensor, torch.Tensor]:
"""
将世界坐标系中的点投影到相机平面
Args:
world_points: [B, 3] 世界坐标系中的点位置
camera_parent_pos: [B, 3] 相机父坐标系的世界位置
camera_parent_quat: [B, 4] 相机父坐标系的世界四元数
return_normalized: 是否返回归一化坐标 [0,1]
Returns:
projected_points: [B, 2] 投影后的点位置
visibility_mask: [B] 可见性掩码 (True=可见, False=不可见)
"""
batch_size = ball_pos.shape[0]
# 1. 计算相机在世界坐标系中的位置和姿态
camera_pos_w, camera_quat_w = combine_frame_transforms(
robot_pos, # [B, 3]
robot_quat, # [B, 4]
self.t_body_cam.expand(batch_size, -1), # [B, 3]
self.q_body_cam.expand(batch_size, -1), # [B, 4]
)
# 2. 将世界坐标转换到相机坐标系
points_in_camera, _ = subtract_frame_transforms(
camera_pos_w, camera_quat_w, ball_pos
)
projected_points = project_points(
points_in_camera, self.intrinsic_matrix
).squeeze(0) # [B, 2]
# projected_points = torch.matmul(self.intrinsic_matrix, points_in_camera.unsqueeze(1)) # [B ,3 ,3] * [B ,1 ,3]
distance = torch.norm(points_in_camera, dim=1)
radius_uv = (self.focal_length * ball_radius / distance).unsqueeze(
1
) # [B, 1] 计算球的半径在图像平面上的投影半径
# 对于不可见的点,设置为 [-1, -1]
# projected_points[~visibility_mask] = -1.0
in_front_mask = points_in_camera[:, 2] > 0.01 # 至少1cm在前方
in_bounds_mask = torch.logical_and(
projected_points[:, 0] >= self.roi_w[0],
projected_points[:, 0] < self.roi_w[1],
) & torch.logical_and(
projected_points[:, 1] >= self.roi_h[0],
projected_points[:, 1] < self.roi_h[1],
)
visibility_mask = in_front_mask & in_bounds_mask # [B]
# 3. 组合可见性掩码
projected_points[~visibility_mask] = torch.tensor(
[self.image_height, self.image_width, -1.0], device=self.device
) #
return projected_points, radius_uv # , visibility_mask |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Issue Description
Problem Summary
I am currently using tiled camera in isaac sim to train my agent. I wanna to project the ball into the image plane using relative pos and camera intrinsics. However, I found that the ball could not project to the right pixel when it gets closer and far from the central(cx,cy). I have calibrated the camera in isaaclab and got the intrinsic, however there is still some difference between the rendering position and the projected position (can be seen in the video).
Environment Details
Similar Case
Not found yet
Additional Information
This is a video to demonstrate my situation
test_projection.mp4
Here is some part of my collection code
Could you please investigate this issue? Thank you for your time and consideration!
Beta Was this translation helpful? Give feedback.
All reactions