Esempio n. 1
0
def main():
    """Interpolates the lidar point cloud using IP-Basic
    and saves a dense depth map of the scene.
    https://github.com/kujason/ip_basic
    """

    ##############################
    # Options
    ##############################

    kitti_raw_dir = os.path.expanduser(
        '/local-scratch/hadi/datasets/kitti_raw')
    drive_id = '2011_09_26_drive_0001_sync'
    # drive_id = '2011_09_26_drive_0039_sync'

    raw_data = raw_utils.get_raw_data(drive_id, kitti_raw_dir)

    # Fill algorithm ('ip_basic_{...}')
    fill_type = 'multiscale'

    save_depth_maps = True

    out_depth_map_dir = core.data_dir() + '/results/{}/depth_02_{}'.format(
        drive_id, fill_type)

    ##############################
    # End of Options
    ##############################
    os.makedirs(out_depth_map_dir, exist_ok=True)

    # Rolling average array of times for time estimation
    avg_time_arr_length = 5
    last_fill_times = np.repeat([1.0], avg_time_arr_length)
    last_total_times = np.repeat([1.0], avg_time_arr_length)

    cam_p = raw_data.calib.P_rect_20

    image_shape = raw_data.get_cam2(0).size[::-1]

    frames_to_use = raw_data.velo_files
    num_frames = len(frames_to_use)

    for frame_idx, velo_path in enumerate(frames_to_use):

        # Calculate average time with last n fill times
        avg_fill_time = np.mean(last_fill_times)
        avg_total_time = np.mean(last_total_times)

        # Print progress
        sys.stdout.write('\rProcessing {} / {}, Avg Fill Time: {:.5f}s, '
                         'Avg Time: {:.5f}s, Est Time: {:.3f}s'.format(
                             frame_idx, num_frames - 1, avg_fill_time,
                             avg_total_time,
                             avg_total_time * (num_frames - frame_idx)))
        sys.stdout.flush()

        # Start timing
        start_total_time = time.time()

        # Load point cloud
        velo_points = raw_data.get_velo(frame_idx)[:, 0:3]
        velo_pc_padded = transform_utils.pad_pc(velo_points.T)

        cam0_point_cloud = raw_data.calib.R_rect_00 @ raw_data.calib.T_cam0_velo @ velo_pc_padded

        cam0_point_cloud, _ = obj_utils.filter_pc_to_area(
            cam0_point_cloud[0:3],
            area_extents=np.asarray([[-40, 40], [-3, 5], [0, 80]]))

        # Project point cloud to create depth map
        projected_depths = depth_map_utils.project_depths(
            cam0_point_cloud, cam_p, image_shape)

        # Fill depth map
        if fill_type == 'multiscale':
            start_fill_time = time.time()
            final_depth_map, _ = ip_basic.fill_in_multiscale(projected_depths)
            end_fill_time = time.time()
        else:
            raise ValueError('Invalid fill algorithm')

        # Save depth maps
        if save_depth_maps:
            out_depth_map_path = out_depth_map_dir + '/{:010d}.png'.format(
                frame_idx)
            depth_map_utils.save_depth_map(out_depth_map_path, final_depth_map)

        # Stop timing
        end_total_time = time.time()

        # Update fill times
        last_fill_times = np.roll(last_fill_times, -1)
        last_fill_times[-1] = end_fill_time - start_fill_time

        # Update total times
        last_total_times = np.roll(last_total_times, -1)
        last_total_times[-1] = end_total_time - start_total_time
Esempio n. 2
0
def main():
    """Interpolates the lidar point cloud using IP-Basic
    and saves a dense depth map of the scene.
    https://github.com/kujason/ip_basic
    """

    ##############################
    # Options
    ##############################

    dataset = DatasetBuilder.build_kitti_obj_dataset(
        DatasetBuilder.KITTI_TRAINVAL)

    # Fill algorithm ('ip_basic_{...}')
    fill_type = 'multiscale'

    save_depth_maps = True

    out_depth_map_dir = 'outputs/obj/depth_2_{}'.format(fill_type)

    samples_to_use = None
    # samples_to_use = ['000764']

    ##############################
    # End of Options
    ##############################
    os.makedirs(out_depth_map_dir, exist_ok=True)

    # Rolling average array of times for time estimation
    avg_time_arr_length = 5
    last_fill_times = np.repeat([1.0], avg_time_arr_length)
    last_total_times = np.repeat([1.0], avg_time_arr_length)

    if samples_to_use is None:
        samples_to_use = [sample.name for sample in dataset.sample_list]

    for sample_idx, sample_name in enumerate(samples_to_use):

        # Calculate average time with last n fill times
        avg_fill_time = np.mean(last_fill_times)
        avg_total_time = np.mean(last_total_times)

        # Print progress
        sys.stdout.write(
            '\rProcessing {} / {}, Idx {}, Avg Fill Time: {:.5f}s, '
            'Avg Time: {:.5f}s, Est Time: {:.3f}s'.format(
                sample_idx, dataset.num_samples - 1, sample_name,
                avg_fill_time, avg_total_time,
                avg_total_time * (dataset.num_samples - sample_idx)))
        sys.stdout.flush()

        # Start timing
        start_total_time = time.time()

        # Load sample info
        image = obj_utils.get_image(sample_name, dataset.image_2_dir)
        image_shape = image.shape[0:2]
        frame_calib = calib_utils.get_frame_calib(dataset.calib_dir,
                                                  sample_name)
        cam_p = frame_calib.p2

        # Load point cloud
        point_cloud = obj_utils.get_lidar_point_cloud(sample_name, frame_calib,
                                                      dataset.velo_dir)

        # Fill depth map
        if fill_type == 'multiscale':
            # Project point cloud to depth map
            projected_depths = depth_map_utils.project_depths(
                point_cloud, cam_p, image_shape)

            start_fill_time = time.time()
            final_depth_map, _ = ip_basic.fill_in_multiscale(projected_depths)
            end_fill_time = time.time()
        else:
            raise ValueError('Invalid fill algorithm')

        # Save depth maps
        if save_depth_maps:
            out_depth_map_path = out_depth_map_dir + '/{}.png'.format(
                sample_name)
            depth_map_utils.save_depth_map(out_depth_map_path, final_depth_map)

        # Stop timing
        end_total_time = time.time()

        # Update fill times
        last_fill_times = np.roll(last_fill_times, -1)
        last_fill_times[-1] = end_fill_time - start_fill_time

        # Update total times
        last_total_times = np.roll(last_total_times, -1)
        last_total_times[-1] = end_total_time - start_total_time