waymo-research / waymo-open-dataset

Waymo Open Dataset
https://www.waymo.com/open
Other
2.66k stars 609 forks source link

The problem about generate point clouds #595

Open gwenzhang opened 1 year ago

gwenzhang commented 1 year ago

` frame = dataset_pb2.Frame()

frame.ParseFromString(bytearray(data.numpy()))

range_images, camera_projections, range_image_top_pose = frame_utils.parse_range_image_and_camera_projection(frame)
points, cp_points, points_in_NLZ_flag, points_intensity, points_elongation = convert_range_image_to_point_cloud(frame, range_images, camera_projections,range_image_top_pose, ri_index=(0, 1))

def convert_range_image_to_point_cloud(frame, range_images, camera_projections, range_image_top_pose, ri_index=(0, 1)):

calibrations = sorted(frame.context.laser_calibrations, key=lambda c: c.name)
points = []
cp_points = []
points_NLZ = []
points_intensity = []
points_elongation = []

frame_pose = tf.convert_to_tensor(np.reshape(np.array(frame.pose.transform), [4, 4]))
range_image_top_pose_tensor = tf.reshape(
    tf.convert_to_tensor(range_image_top_pose.data), range_image_top_pose.shape.dims
)
range_image_top_pose_tensor_rotation = transform_utils.get_rotation_matrix(
    range_image_top_pose_tensor[..., 0], range_image_top_pose_tensor[..., 1],
    range_image_top_pose_tensor[..., 2])
range_image_top_pose_tensor_translation = range_image_top_pose_tensor[..., 3:]
range_image_top_pose_tensor = transform_utils.get_transform(
    range_image_top_pose_tensor_rotation,
    range_image_top_pose_tensor_translation)

for c in calibrations:
    points_single, cp_points_single, points_NLZ_single, points_intensity_single, points_elongation_single \
        = [], [], [], [], []
    for cur_ri_index in ri_index:
        range_image = range_images[c.name][cur_ri_index]
        if len(c.beam_inclinations) == 0:  # pylint: disable=g-explicit-length-test
            beam_inclinations = range_image_utils.compute_inclination(
                tf.constant([c.beam_inclination_min, c.beam_inclination_max]),
                height=range_image.shape.dims[0])
        else:
            beam_inclinations = tf.constant(c.beam_inclinations)

        beam_inclinations = tf.reverse(beam_inclinations, axis=[-1])
        extrinsic = np.reshape(np.array(c.extrinsic.transform), [4, 4])

        range_image_tensor = tf.reshape(
            tf.convert_to_tensor(range_image.data), range_image.shape.dims)
        pixel_pose_local = None
        frame_pose_local = None
        if c.name == dataset_pb2.LaserName.TOP:
            pixel_pose_local = range_image_top_pose_tensor
            pixel_pose_local = tf.expand_dims(pixel_pose_local, axis=0)
            frame_pose_local = tf.expand_dims(frame_pose, axis=0)
        range_image_mask = range_image_tensor[..., 0] > 0
        range_image_NLZ = range_image_tensor[..., 3]
        range_image_intensity = range_image_tensor[..., 1]
        range_image_elongation = range_image_tensor[..., 2]
        range_image_cartesian = range_image_utils.extract_point_cloud_from_range_image(
            tf.expand_dims(range_image_tensor[..., 0], axis=0),
            tf.expand_dims(extrinsic, axis=0),
            tf.expand_dims(tf.convert_to_tensor(beam_inclinations), axis=0),
            pixel_pose=pixel_pose_local,
            frame_pose=frame_pose_local)   ########## !!!!!!!!!!!!!!!!!

        range_image_cartesian = tf.squeeze(range_image_cartesian, axis=0)
        points_tensor = tf.gather_nd(range_image_cartesian, tf.where(range_image_mask))
        points_NLZ_tensor = tf.gather_nd(range_image_NLZ, tf.compat.v1.where(range_image_mask))
        points_intensity_tensor = tf.gather_nd(range_image_intensity, tf.compat.v1.where(range_image_mask))
        points_elongation_tensor = tf.gather_nd(range_image_elongation, tf.compat.v1.where(range_image_mask))
        cp = camera_projections[c.name][0]
        cp_tensor = tf.reshape(tf.convert_to_tensor(cp.data), cp.shape.dims)
        cp_points_tensor = tf.gather_nd(cp_tensor, tf.where(range_image_mask))

        points_single.append(points_tensor.numpy())
        cp_points_single.append(cp_points_tensor.numpy())
        points_NLZ_single.append(points_NLZ_tensor.numpy())
        points_intensity_single.append(points_intensity_tensor.numpy())
        points_elongation_single.append(points_elongation_tensor.numpy())

    points.append(np.concatenate(points_single, axis=0))
    cp_points.append(np.concatenate(cp_points_single, axis=0))
    points_NLZ.append(np.concatenate(points_NLZ_single, axis=0))
    points_intensity.append(np.concatenate(points_intensity_single, axis=0))
    points_elongation.append(np.concatenate(points_elongation_single, axis=0))

return points, cp_points, points_NLZ, points_intensity, points_elongation

` The returned points are wrong. For example, the size of one return points[0] are (188774,3). When I use np.unique(points[0], axis=0), it returns (6924, 3). But it is correct for point[1-4].

alexgorban commented 1 year ago

Sorry for the delayed response. Do you still observe the issue? Can you please share values of Frame.context.name and Frame.timestamp_micros for the frame where you observe this issue?

wellneck commented 1 year ago

got the same problem