Exemplo n.º 1
0
def display_next_frame(event=None):
    global once

    frame = next(datafile_iter)

    # Get the top laser information
    laser_name = dataset_pb2.LaserName.TOP
    laser = utils.get(frame.lasers, laser_name)
    laser_calibration = utils.get(frame.context.laser_calibrations, laser_name)

    # Parse the top laser range image and get the associated projection.
    ri, camera_projection, range_image_pose = utils.parse_range_image_and_camera_projection(
        laser)

    # Convert the range image to a point cloud.
    pcl, pcl_attr = utils.project_to_pointcloud(frame, ri, camera_projection,
                                                range_image_pose,
                                                laser_calibration)

    # Update the geometry and render the pointcloud
    pcd.points = o3d.utility.Vector3dVector(pcl)
    if once:
        vis.add_geometry(pcd)
        once = False
    else:
        vis.update_geometry(pcd)
 def get_image(self, frame, idx):
     '''Get image
     '''
     camera_name = dataset_pb2.CameraName.FRONT
     camera_calibration = utils.get(frame.context.camera_calibrations, camera_name)
     camera = utils.get(frame.images, camera_name)
     vehicle_to_image = utils.get_image_transform(camera_calibration) # Transformation
     img = utils.decode_image(camera)
     self.image=img
     return img
 def get_lidar(self, frame, idx, all_points=False):
     '''Get lidar pointcloud
         TODO: Get all 4 lidar points appeneded together
         :return pcl: (N, 3) points in (x,y,z)
     '''
     laser_name = dataset_pb2.LaserName.TOP # laser information
     laser = utils.get(frame.lasers, laser_name)
     laser_calibration = utils.get(frame.context.laser_calibrations, laser_name)
     ri, camera_projection, range_image_pose = utils.parse_range_image_and_camera_projection(laser)
     pcl, pcl_attr = utils.project_to_pointcloud(frame, ri, camera_projection, range_image_pose, laser_calibration)
     return pcl
Exemplo n.º 4
0
def get_calibration(
    frame: dataset_pb2.Frame, camera_id: int
) -> Tuple[ImageSize, Intrinsics, Extrinsics, Extrinsics, Extrinsics]:
    """Load and decode calibration data of camera in frame."""
    calib = utils.get(frame.context.camera_calibrations, camera_id)

    image_size = ImageSize(height=calib.height, width=calib.width)

    intrinsics = Intrinsics(
        focal=(calib.intrinsic[0], calib.intrinsic[1]),
        center=(calib.intrinsic[2], calib.intrinsic[3]),
    )

    cam2car_mat: NDArrayF64 = np.array(calib.extrinsic.transform,
                                       dtype=np.float64).reshape(4, 4)
    car2cam_mat = np.linalg.inv(cam2car_mat)
    car2cam_mat = np.dot(waymo2kitti_RT, car2cam_mat)
    cam2car_mat = np.linalg.inv(car2cam_mat)

    car2global_mat: NDArrayF64 = np.array(frame.pose.transform,
                                          dtype=np.float64).reshape(4, 4)
    cam2global_mat = np.dot(car2global_mat, cam2car_mat)

    cam2car = get_extrinsics_from_matrix(cam2car_mat)
    car2global = get_extrinsics_from_matrix(car2global_mat)
    cam2global = get_extrinsics_from_matrix(cam2global_mat)

    return (
        image_size,
        intrinsics,
        cam2car,
        car2global,
        cam2global,
    )
Exemplo n.º 5
0
def export_file(filename):
    print('[{}] Porting: {}'.format(threading.get_ident(), filename))
    head, tail = os.path.split(filename)
    m = re.search('(.*)(_with_camera_labels)?\.tfrecord$', tail)
    if m is None:
        exit(1)
    filename_without_tfrecord = m.group(1)

    _start_time = time.time()
    # waymo data file reader
    datafile = WaymoDataFileReader(filename)

    # Generate a table of the offset of all frame records in the file.
    table = datafile.get_record_table()

    print("There are %d frames in this file." % len(table))

    # Loop through the whole file
    ## and display 3D labels.
    frame_id = 0
    for frame in datafile:
        camera_name = dataset_pb2.CameraName.FRONT
        camera_calibration = utils.get(frame.context.camera_calibrations,
                                       camera_name)
        camera = utils.get(frame.images, camera_name)

        camera_labels = None
        if len(frame.camera_labels) != 0:
            camera_labels = utils.get(frame.camera_labels, camera_name)
            camera_labels = camera_labels.labels

        exporter.export(camera_calibration,
                        camera,
                        frame.laser_labels,
                        camera_labels,
                        frame_id=frame_id,
                        sequence_id=filename_without_tfrecord)
        frame_id += 1
    print('[{}] Processed file in {}'.format(threading.get_ident(),
                                             time.time() - _start_time))
filename = sys.argv[1]
datafile = WaymoDataFileReader(filename)

# Generate a table of the offset of all frame records in the file.
table = datafile.get_record_table()

print("There are %d frames in this file." % len(table))


# Loop through the whole file
## and display 3D labels.
for frameno,frame in enumerate(datafile):

    # Get the top laser information
    laser_name = dataset_pb2.LaserName.TOP
    laser = utils.get(frame.lasers, laser_name)
    laser_calibration = utils.get(frame.context.laser_calibrations, laser_name)

    # Parse the top laser range image and get the associated projection.
    ri, camera_projection, range_image_pose = utils.parse_range_image_and_camera_projection(laser)

    # Convert the range image to a point cloud.
    pcl, pcl_attr = utils.project_to_pointcloud(frame, ri, camera_projection, range_image_pose, laser_calibration)

    # Get the front camera information
    camera_name = dataset_pb2.CameraName.FRONT
    camera_calibration = utils.get(frame.context.camera_calibrations, camera_name)
    camera = utils.get(frame.images, camera_name)

    # Get the transformation matrix for the camera.
    vehicle_to_image = utils.get_image_transform(camera_calibration)
    frame_number = 0

    for frame in frames:

        num_points = 0
        num_features = 7
        point_cloud_list = []

        for laser_id in range(1, 6):

            laser_name = dataset_pb2.LaserName.Name.DESCRIPTOR.values_by_number[
                laser_id].name

            # Get the laser information
            laser = utils.get(frame.lasers, laser_id)
            laser_calibration = utils.get(frame.context.laser_calibrations,
                                          laser_id)

            # Parse the top laser range image and get the associated projection.
            ri, camera_projection, range_image_pose = utils.parse_range_image_and_camera_projection(
                laser)

            # Convert the range image to a point cloud.
            pcl, pcl_attr = utils.project_to_pointcloud(
                frame, ri, camera_projection, range_image_pose,
                laser_calibration)

            pcl_with_attr = np.column_stack((pcl, pcl_attr))

            num_points += len(pcl)
Exemplo n.º 8
0
filenames = list(sorted(filenames))
datafile = WaymoDataFileReader(filenames[23])

# Generate a table of the offset of all frame records in the file.
table = datafile.get_record_table()

print("There are %d frames in this file." % len(table))

# Loop through the whole file
## and display 3D labels.
i = 0
for frame in datafile:
    i += 1
    if i == 1:
        camera_name = dataset_pb2.CameraName.SIDE_RIGHT
        camera_calibration = utils.get(frame.context.camera_calibrations,
                                       camera_name)
        camera = utils.get(frame.images, camera_name)
        display_labels_on_image(camera_calibration, camera, frame.laser_labels,
                                10)

# Alternative: Displaying a single frame:
# # Jump to the frame 150
# datafile.seek(table[150])
#
# # Read and display this frame
# frame = datafile.read_record()
# display_labels_on_image(frame.context.camera_calibrations[0], frame.images[0], frame.laser_labels)

# Alternative: Displaying a 10 frames:
# # Jump to the frame 150
# datafile.seek(table[150])
Exemplo n.º 9
0
def parse_frame(
    frame: dataset_pb2.Frame,
    frame_id: int,
    output_dir: str,
    save_images: bool = False,
    use_lidar_labels: bool = False,
) -> Tuple[List[Frame], List[FrameGroup]]:
    """Parse information in single frame to Scalabel Frame per camera."""
    frame_name = frame.context.name + f"_{frame_id:07d}.jpg"
    attributes = parse_frame_attributes(frame, use_lidar_labels)

    results, group_results = [], []
    frame_names = []
    sequence = frame.context.name
    for camera_id, camera in cameras_id2name.items():
        (
            image_size,
            intrinsics,
            cam2car,
            car2global,
            cam2global,
        ) = get_calibration(frame, camera_id)
        url = os.path.join(sequence, camera, frame_name)
        img_filepath = os.path.join(output_dir, sequence, camera, frame_name)

        img_name = (frame.context.name + "_" + camera.lower() +
                    f"_{frame_id:07d}.jpg")

        if save_images and not os.path.exists(img_filepath):
            if not os.path.exists(os.path.dirname(img_filepath)):
                os.makedirs(os.path.dirname(img_filepath))
            im_bytes = utils.get(frame.images, camera_id).image
            with open(img_filepath, "wb") as fp:
                fp.write(im_bytes)

        if use_lidar_labels:
            labels = parse_lidar_labels(frame, cam2car, camera, camera_id)
        else:
            labels = parse_camera_labels(frame, camera_id)

        f = Frame(
            name=img_name,
            videoName=sequence,
            frameIndex=frame_id,
            url=url,
            size=image_size,
            extrinsics=cam2global,
            intrinsics=intrinsics,
            labels=labels,
            attributes=attributes,
        )
        frame_names.append(img_name)
        results.append(f)

    url = f"segment-{frame.context.name}_with_camera_labels.tfrecord"

    lidar2car_mat: NDArrayF64 = np.array(
        frame.context.laser_calibrations[
            lasers_name2id["TOP"]].extrinsic.transform,
        dtype=np.float64,
    ).reshape(4, 4)
    lidar2global_mat = np.dot(get_matrix_from_extrinsics(car2global),
                              lidar2car_mat)

    lidar2car = get_extrinsics_from_matrix(lidar2car_mat)
    lidar2global = get_extrinsics_from_matrix(lidar2global_mat)

    group_results = [
        FrameGroup(
            name=frame_name,
            videoName=sequence,
            frameIndex=frame_id,
            url=url,
            extrinsics=lidar2global,
            frames=frame_names,
            labels=parse_lidar_labels(frame, lidar2car),
        )
    ]

    return results, group_results