(
input_path: Path,
output_sparse_path: Path,
output_dense_path: Path,
workspace_path: Path,
)
| 21 | @click.argument("output_dense_path", type=click.Path(path_type=Path)) |
| 22 | @click.argument("workspace_path", type=click.Path(path_type=Path)) |
| 23 | def main( |
| 24 | input_path: Path, |
| 25 | output_sparse_path: Path, |
| 26 | output_dense_path: Path, |
| 27 | workspace_path: Path, |
| 28 | ) -> None: |
| 29 | # Load the FlowMap configuration. |
| 30 | with Path("config/overfit.yaml").open("r") as f: |
| 31 | cfg = yaml.safe_load(f) |
| 32 | cfg = get_typed_config(CroppingCfg, DictConfig(cfg["cropping"])) |
| 33 | |
| 34 | # Then, we crop the input images to the appropriate shape. |
| 35 | resized_images_dir = workspace_path / "resized_images" |
| 36 | resized_images_dir.mkdir(exist_ok=True, parents=True) |
| 37 | for image_path in tqdm(list(input_path.iterdir()), desc="Resizing images"): |
| 38 | image = Image.open(image_path) |
| 39 | |
| 40 | h_original = image.height |
| 41 | w_original = image.width |
| 42 | |
| 43 | h, w = ( |
| 44 | dim * cfg.flow_scale_multiplier |
| 45 | for dim in get_image_shape((image.height, image.width), cfg) |
| 46 | ) |
| 47 | image = image.resize((w, h), Image.LANCZOS) |
| 48 | image.save(resized_images_dir / image_path.name) |
| 49 | |
| 50 | # Run sparse COLMAP. |
| 51 | resized_sparse_dir = workspace_path / "resized_sparse" |
| 52 | run_sparse(resized_images_dir, resized_sparse_dir, 0, "extreme", "video") |
| 53 | |
| 54 | # Run dense COLMAP. |
| 55 | resized_dense_dir = workspace_path / "resized_dense" |
| 56 | run_dense(resized_sparse_dir, resized_dense_dir) |
| 57 | |
| 58 | def resize_metadata(path: Path) -> None: |
| 59 | extrinsics, intrinsics, image_names = read_colmap_model(path) |
| 60 | write_colmap_model( |
| 61 | path, |
| 62 | extrinsics, |
| 63 | intrinsics, |
| 64 | image_names, |
| 65 | (h_original, w_original), |
| 66 | ) |
| 67 | |
| 68 | # Copy and rescale the sparse outputs. |
| 69 | print("Resizing sparse outputs.") |
| 70 | output_sparse_path.parent.mkdir(exist_ok=True, parents=True) |
| 71 | shutil.copytree(resized_sparse_dir, output_sparse_path) |
| 72 | shutil.rmtree(output_sparse_path / "images") |
| 73 | shutil.copytree(input_path, output_sparse_path / "images") |
| 74 | resize_metadata(output_sparse_path / "sparse/0") |
| 75 | (output_sparse_path / "sparse/0/points3D.bin").unlink() |
| 76 | shutil.copy( |
| 77 | resized_sparse_dir / "sparse/0/points3D.bin", |
| 78 | output_sparse_path / "sparse/0/points3D.bin", |
| 79 | ) |
| 80 |
no test coverage detected