visibilitydataset / visibilitydataset.github.io

MIT License
5 stars 0 forks source link

Point clouds generate depth maps #4

Open xuefei1998 opened 1 year ago

xuefei1998 commented 1 year ago

Thank you very much for your work. When I converted the point cloud into the depth map, the result I got was a longitudinal depth map, which seemed to be the result after rotation of 90 degrees and could not be registered with the image. Here is my code, may I ask what is wrong with it? Or can you provide a code to turn the point cloud into a depth map?

def pc2dm():
    cloud = pc2.read_points(msg, skip_nans=True, field_names=("x", "y", "z"))
    # Load the point cloud data into a numpy array
    point_cloud = np.array(list(cloud))
    T = T_lidar_rgb
    K = camera_rgb
    point_cloud = np.dot(T, point_cloud.T).T[:, :3]
    print(point_cloud.shape)
    print(point_cloud[0])
    img_points, _ = cv2.projectPoints(point_cloud, np.zeros(3), np.zeros(3), K, np.zeros(5))
    print(img_points.shape)
    print(img_points[0])
    img_points = np.round(img_points).astype(int)
    valid_mask = np.logical_and.reduce((img_points[:, 0, 0] >= 0, img_points[:, 0, 0] < 1280,
                                     img_points[:, 0, 1] >= 0, img_points[:, 0, 1] < 1024))
    img_points = img_points[valid_mask]
    depth_map = np.zeros((1024, 1280))
    depth_map[img_points[:, 0, 1], img_points[:, 0, 0]] = point_cloud[valid_mask, 2]
    return depth_map