mileyan / pseudo_lidar

(CVPR 2019) Pseudo-LiDAR from Visual Depth Estimation: Bridging the Gap in 3D Object Detection for Autonomous Driving
https://mileyan.github.io/pseudo_lidar/
MIT License
966 stars 214 forks source link

How to display point cloud in image plane? #28

Open sarimmehdi opened 4 years ago

sarimmehdi commented 4 years ago

Hello, with the default kitti velodyne data, I was able to project the point cloud onto the image plane using this code:

   vld = np.fromfile(os.path.join(args.kitti_loc, 'velodyne', velo_files[seg_counter]), dtype=np.float32)
   vld = vld.reshape((-1, 4)).T

    # Reshape calibration files
    P2 = clb['P2']
    R0 = np.eye(4)
    R0[:-1, :-1] = clb['R0_rect']
    Tr = np.eye(4)
    Tr[:-1, :] = clb['Tr_velo_to_cam']

    # Prepare 3d points
    pts3d = vld[:, vld[-1, :] > 0].copy()
    pts3d[-1, :] = 1

    # Project 3d points
    pts3d_cam = np.matmul(np.matmul(R0, Tr), pts3d)
    mask = pts3d_cam[2, :] >= 0  # Z >= 0
    pts2d_cam = np.matmul(P2, pts3d_cam[:, mask])
    pts2d = (pts2d_cam / pts2d_cam[2, :])[:-1, :].T

    # draw points on img
    height, width, channels = mask_img.shape
    blank_image = np.zeros((height, width, channels), np.uint8)
    for x in range(pts2d.shape[0]):
        xcolor = int(pts2d[x, 0])
        ycolor = int(pts2d[x, 1])
        if 0 <= xcolor < img.shape[1] and 0 <= ycolor < img.shape[0]:
            blank_image[ycolor, xcolor, :] = colors['pink']

    cv2.imshow('', blank_image)
    cv2.waitKey(100)

This displays the point cloud correctly on the image plane: normal_vel However, when I use the same code to display your point cloud, I get this: pseudo_lidar_vel

I know that the depth map was generated correctly (and shockingly accurate might I add) so can you please tell me how to project your point cloud onto the image plane? Thanks!

mileyan commented 4 years ago

Hi You can use this script to generate depth maps from point clouds https://github.com/mileyan/pseudo_lidar/blob/master/preprocessing/generate_disp.py. But you have to comment out this line https://github.com/mileyan/pseudo_lidar/blob/master/preprocessing/generate_disp.py#L25.