ns-process-data: fix image renaming for the --skip-colmap case (#1459)

* Fix ns-process-data with skip colmap

* Fix docstring

* Fix pylint problem

* Change OrderedDict to dict
This commit is contained in:
Jonáš Kulhánek authored and GitHub committed 2023-02-24 20:40:52 -08:00
1 parent a28442a82c
commit 7e9af33c03
3 files changed
+24 -9

No files matched your search

+5 -1
View File
@@ -587,6 +587,7 @@ def colmap_to_json(
output_dir: Path,
camera_model: CameraModel,
camera_mask_path: Optional[Path] = None,
image_rename_map: Optional[Dict[str, str]] = None,
) -> int:
"""Converts COLMAP's cameras.bin and images.bin to a JSON file.
@@ -619,7 +620,10 @@ def colmap_to_json(
c2w = c2w[np.array([1, 0, 2, 3]), :]
c2w[2, :] *= -1
name = Path(f"./images/{im_data.name}")
name = im_data.name
if image_rename_map is not None:
name = image_rename_map[name]
name = Path(f"./images/{name}")
frame = {
"file_path": name.as_posix(),
@@ -24,7 +24,7 @@ from typing import List, Optional, Tuple
import cv2
import numpy as np
from rich.console import Console
from typing_extensions import Literal
from typing_extensions import Literal, OrderedDict
from nerfstudio.utils.rich_utils import status
from nerfstudio.utils.scripts import run_command
@@ -242,7 +242,7 @@ def copy_and_upscale_polycam_depth_maps_list(
return copied_depth_map_paths
def copy_images(data: Path, image_dir: Path, verbose) -> int:
def copy_images(data: Path, image_dir: Path, verbose) -> OrderedDict[Path, Path]:
"""Copy images from a directory to a new directory.
Args:
@@ -250,7 +250,7 @@ def copy_images(data: Path, image_dir: Path, verbose) -> int:
image_dir: Path to the output directory.
verbose: If True, print extra logging.
Returns:
The number of images copied.
The mapping from the original filenames to the new ones.
"""
with status(msg="[bold yellow]Copying images...", spinner="bouncingBall", verbose=verbose):
image_paths = list_images(data)
@@ -259,9 +259,8 @@ def copy_images(data: Path, image_dir: Path, verbose) -> int:
CONSOLE.log("[bold red]:skull: No usable images in the data folder.")
sys.exit(1)
num_frames = len(copy_images_list(image_paths=image_paths, image_dir=image_dir, verbose=verbose))
return num_frames
copied_images = copy_images_list(image_paths=image_paths, image_dir=image_dir, verbose=verbose)
return OrderedDict((original_path, new_path) for original_path, new_path in zip(image_paths, copied_images))
def downscale_images(image_dir: Path, num_downscales: int, folder_name: str = "images", verbose: bool = False) -> str: