Exemplo n.º 1
0
def process_frame(params):
    image0_path, image1_path, image2_path, \
        sparse_depth_path, semi_dense_depth_path = params

    # Read images and concatenate together
    image0 = cv2.imread(image0_path)
    image1 = cv2.imread(image1_path)
    image2 = cv2.imread(image2_path)
    image = np.concatenate([image1, image0, image2], axis=1)

    sz, vm = data_utils.load_depth_with_validity_map(sparse_depth_path)
    iz = data_utils.interpolate_depth(sz, vm)

    # Create validity map and image output path
    interp_depth_output_path = sparse_depth_path \
        .replace(KITTI_DEPTH_COMPLETION_DIRPATH, KITTI_DEPTH_COMPLETION_OUTPUT_DIRPATH) \
        .replace('sparse_depth', 'interp_depth')
    validity_map_output_path = sparse_depth_path \
        .replace(KITTI_DEPTH_COMPLETION_DIRPATH, KITTI_DEPTH_COMPLETION_OUTPUT_DIRPATH) \
        .replace('sparse_depth', 'validity_map')
    image_output_path = validity_map_output_path \
        .replace(os.path.join(os.sep+'proj_depth', 'velodyne_raw'), '') \
        .replace('validity_map', 'image')

    # Create output directories
    for output_path in [
            image_output_path, interp_depth_output_path,
            validity_map_output_path
    ]:
        output_dirpath = os.path.dirname(output_path)
        if not os.path.exists(output_dirpath):
            try:
                os.makedirs(output_dirpath)
            except FileExistsError:
                pass

    # Write to disk
    data_utils.save_depth(iz, interp_depth_output_path)
    data_utils.save_validity_map(vm, validity_map_output_path)
    cv2.imwrite(image_output_path, image)

    return (image_output_path, sparse_depth_path, interp_depth_output_path,
            validity_map_output_path, semi_dense_depth_path)
def process_frame(args):
    image_path1, image_path0, image_path2, \
        sparse_depth_path, validity_map_path, ground_truth_path = args

    # Create image composite of triplets
    im1 = cv2.imread(image_path1)
    im0 = cv2.imread(image_path0)
    im2 = cv2.imread(image_path2)
    imc = np.concatenate([im1, im0, im2], axis=1)

    # Create interpolated depth
    sz, vm = data_utils.load_depth_with_validity_map(sparse_depth_path)
    iz = data_utils.interpolate_depth(sz, vm)

    image_ref_path = os.path.join(*image_path0.split(os.sep)[2:])
    sparse_depth_ref_path = os.path.join(*sparse_depth_path.split(os.sep)[2:])
    # Set output paths
    image_output_path = os.path.join(VOID_OUT_DIRPATH, image_ref_path)
    sparse_depth_output_path = sparse_depth_path
    interp_depth_output_path = os.path.join(VOID_OUT_DIRPATH, sparse_depth_ref_path) \
        .replace('sparse_depth', 'interp_depth')
    validity_map_output_path = validity_map_path
    ground_truth_output_path = ground_truth_path

    # Verify that all filenames match
    image_out_dirpath, image_filename = os.path.split(image_output_path)
    sparse_depth_filename = os.path.basename(sparse_depth_output_path)
    validity_map_filename = os.path.basename(validity_map_output_path)
    ground_truth_filename = os.path.basename(ground_truth_output_path)
    assert (image_filename == sparse_depth_filename)
    assert (image_filename == validity_map_filename)
    assert (image_filename == ground_truth_filename)

    # Write to disk
    cv2.imwrite(image_output_path, imc)
    data_utils.save_depth(iz, interp_depth_output_path)

    return (image_ref_path, image_output_path, sparse_depth_output_path,
            interp_depth_output_path, validity_map_output_path,
            ground_truth_output_path)
def process_frame(args):
  sparse_depth_path, validity_map_path = args

  # Create interpolated depth
  sz, vm = data_utils.load_depth_with_validity_map(sparse_depth_path)
  iz = data_utils.interpolate_depth(sz, vm)

  sparse_depth_ref_path = os.path.join(*sparse_depth_path.split(os.sep)[5:])
  
  # Set output paths
  sparse_depth_output_path = sparse_depth_path
  interp_depth_output_path = os.path.join(VOID_OUT_DIRPATH, sparse_depth_ref_path) \
      .replace('sparse_depth', 'interp_depth')
  validity_map_output_path = validity_map_path

  sparse_depth_filename = os.path.basename(sparse_depth_output_path)
  validity_map_filename = os.path.basename(validity_map_output_path)

  # Write to disk
  data_utils.save_depth(iz, interp_depth_output_path)

  return (sparse_depth_ref_path, sparse_depth_output_path, interp_depth_output_path, validity_map_output_path)
def depth_transform(depths, masks, transform_type=None, value=1.0):
    '''
    Applies transformation to depth maps

    Args:
        depths : tensor
            N x C x H x W depth maps
        masks : tensor
            N x C x H x W binary masks
        transform_type : list[str]
            transformations to apply to depth maps
        values : float
            multiplier/shift constant used for transformation

    Returns:
        tensor : transformed depth map
    '''

    masks_inverse = 1.0 - masks

    if 'flip_horizontal' in transform_type:
        depths = flip_horizontal(depths)

    if 'flip_vertical' in transform_type:
        depths = flip_vertical(depths)

    if 'multiply' in transform_type:
        depths_mask = masks * (value * depths)
        depths_mask_inverse = masks_inverse * depths
        depths = depths_mask + depths_mask_inverse

    if 'translate_horizontal' in transform_type:
        depths = translate_horizontal(depths, value)

    if 'translate_vertical' in transform_type:
        depths = translate_vertical(depths, value)

    if 'remove' in transform_type:
        # Get locations to remove and interpolate
        validity_map = torch.squeeze(1.0 - masks)
        valid_depths = torch.squeeze(validity_map * depths)

        interp_depths = data_utils.interpolate_depth(
            valid_depths.detach().cpu().numpy(),
            validity_map.detach().cpu().numpy())

        depths = torch.from_numpy(interp_depths.astype(np.float32))

        if masks.device.type == 'cuda':
            depths = depths.cuda()

        depths = depths.view(masks.shape)

    if 'move_horizontal' in transform_type:
        # Copy the instance from the depth map and translate
        instances = masks * depths
        move_instances = translate_horizontal(instances, value)
        move_map = translate_horizontal(masks, value)

        # Remove the instance from the scene first
        validity_map = torch.squeeze(1.0 - masks)
        valid_depths = torch.squeeze(validity_map * depths)

        interp_depths = data_utils.interpolate_depth(
            valid_depths.detach().cpu().numpy(),
            validity_map.detach().cpu().numpy())

        depths = torch.from_numpy(interp_depths.astype(np.float32))

        if masks.device.type == 'cuda':
            depths = depths.cuda()

        depths = (1.0 - move_map) * depths + move_instances

    if 'move_vertical' in transform_type:
        # Copy the instance from the depth map and translate
        instances = masks * depths
        move_instances = translate_vertical(instances, value)
        move_map = translate_vertical(masks, value)

        # Remove the instance from the scene first
        validity_map = torch.squeeze(1.0 - masks)
        valid_depths = torch.squeeze(validity_map * depths)

        interp_depths = data_utils.interpolate_depth(
            valid_depths.detach().cpu().numpy(),
            validity_map.detach().cpu().numpy())

        depths = torch.from_numpy(interp_depths.astype(np.float32))

        if masks.device.type == 'cuda':
            depths = depths.cuda()

        depths = (1.0 - move_map) * depths + move_instances

    return depths
Exemplo n.º 5
0
            if refdir == 'image':
                image = cv2.imread(path)
                image = np.concatenate([image, image, image], axis=1)
                image_output_path = path \
                    .replace('kitti_depth_completion', 'kitti_depth_completion_voiced')
                image_output_paths.append(image_output_path)

                if not os.path.exists(os.path.dirname(image_output_path)):
                    os.makedirs(os.path.dirname(image_output_path))
                # Write to disk
                cv2.imwrite(image_output_path, image)

            elif refdir == 'sparse_depth':
                # Load sparse depth and save validity map
                sz, vm = data_utils.load_depth_with_validity_map(path)
                iz = data_utils.interpolate_depth(sz, vm)
                # Create validity map output path
                interp_depth_output_path = path \
                    .replace('kitti_depth_completion', 'kitti_depth_completion_voiced') \
                    .replace('sparse_depth', 'interp_depth')
                validity_map_output_path = path \
                    .replace('kitti_depth_completion', 'kitti_depth_completion_voiced') \
                    .replace('sparse_depth', 'validity_map')
                sparse_depth_output_paths.append(path)
                interp_depth_output_paths.append(interp_depth_output_path)
                validity_map_output_paths.append(validity_map_output_path)

                for output_path in [
                        interp_depth_output_path, validity_map_output_path
                ]:
                    output_dirpath = os.path.dirname(output_path)