def transform_grid(self, voxel_grid, grid_to_lidar, lidar_to_cam, cam_to_img): """ Transforms voxel sampling grid into frustum sampling grid Args: voxel_grid [torch.Tensor(B, X, Y, Z, 3)]: Voxel sampling grid grid_to_lidar [torch.Tensor(4, 4)]: Voxel grid to LiDAR unprojection matrix lidar_to_cam [torch.Tensor(B, 4, 4)]: LiDAR to camera frame transformation cam_to_img [torch.Tensor(B, 3, 4)]: Camera projection matrix Returns: frustum_grid [torch.Tensor(B, X, Y, Z, 3)]: Frustum sampling grid """ # B是相机数目 B = lidar_to_cam.shape[0] # Create transformation matricies V_G = grid_to_lidar # Voxel Grid -> LiDAR (4, 4) C_V = lidar_to_cam # LiDAR -> Camera (B, 4, 4) I_C = cam_to_img # Camera -> Image (B, 3, 4) trans = C_V @ V_G # grid转到lidar实际坐标,再转到相机坐标再转到像素。主要是为了grid和像素对应。 # Reshape to match dimensions trans = trans.reshape(B, 1, 1, 4, 4) voxel_grid = voxel_grid.repeat_interleave(repeats=B, dim=0) # Transform to camera frame #camera_grid shape: B X Y Z 3 camera_grid = kornia.transform_points(trans_01=trans, points_1=voxel_grid) # Project to image I_C = I_C.reshape(B, 1, 1, 3, 4) # image_grid shape: B X Y Z 2; image_depth B X Y Z 1 image_grid, image_depths = transform_utils.project_to_image( project=I_C, points=camera_grid) # Convert depths to depth bins # Image_depths.shape: B X Y Z 1 落在哪个bin image_depths = depth_utils.bin_depths(depth_map=image_depths, **self.disc_cfg) # Stack to form frustum grid image_depths = image_depths.unsqueeze(-1) # frustum_grid = B X Y Z 3 frustum_grid = torch.cat((image_grid, image_depths), dim=-1) return frustum_grid
def transform_grid(self, voxel_grid, grid_to_lidar, lidar_to_cam, cam_to_img): """ Transforms voxel sampling grid into frustum sampling grid Args: grid: (B, X, Y, Z, 3), Voxel sampling grid grid_to_lidar: (4, 4), Voxel grid to LiDAR unprojection matrix lidar_to_cam: (B, 4, 4), LiDAR to camera frame transformation cam_to_img: (B, 3, 4), Camera projection matrix Returns: frustum_grid: (B, X, Y, Z, 3), Frustum sampling grid """ B = lidar_to_cam.shape[0] # Create transformation matricies V_G = grid_to_lidar # Voxel Grid -> LiDAR (4, 4) C_V = lidar_to_cam # LiDAR -> Camera (B, 4, 4) I_C = cam_to_img # Camera -> Image (B, 3, 4) trans = C_V @ V_G # Reshape to match dimensions trans = trans.reshape(B, 1, 1, 4, 4) voxel_grid = voxel_grid.repeat_interleave(repeats=B, dim=0) # Transform to camera frame camera_grid = kornia.transform_points(trans_01=trans, points_1=voxel_grid) # Project to image I_C = I_C.reshape(B, 1, 1, 3, 4) image_grid, image_depths = transform_utils.project_to_image( project=I_C, points=camera_grid) # Convert depths to depth bins image_depths = transform_utils.bin_depths(depth_map=image_depths, **self.disc_cfg) # Stack to form frustum grid image_depths = image_depths.unsqueeze(-1) frustum_grid = torch.cat((image_grid, image_depths), dim=-1) return frustum_grid