mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-15 12:23:46 +08:00
Improve ns-process-data images when using existing COLMAP model (#1371)
* Allow skipping copy+downscale of images in ns-process-data, fix bug when using --skip-colmap on images.bin with non-standard image names * Rename flags and improve error messages --------- Co-authored-by: Matthew Tancik <tancik@berkeley.edu>
This commit is contained in:
1 parent
6136745d75
commit
2ff1d3b19e
3 files changed
+98
-40
No files matched your search
@@ -604,6 +604,14 @@ def colmap_to_json(
|
||||
cameras = read_cameras_binary(cameras_path)
|
||||
images = read_images_binary(images_path)
|
||||
|
||||
# Images were renamed to frame_{i:05d}.{ext} and
|
||||
# the filenames needs to be replaced in the transforms.json as well
|
||||
original_filenames = [x.name for x in images.values()]
|
||||
# Sort was used in nerfstudio.process_data.process_data_utils:get_image_filenames
|
||||
original_filenames.sort()
|
||||
# Build the map to the new filenames
|
||||
filename_map = {name: f"frame_{i+1:05d}{os.path.splitext(name)[-1]}" for i, name in enumerate(original_filenames)}
|
||||
|
||||
# Only supports one camera
|
||||
camera_params = cameras[1].params
|
||||
|
||||
@@ -619,7 +627,8 @@ def colmap_to_json(
|
||||
c2w = c2w[np.array([1, 0, 2, 3]), :]
|
||||
c2w[2, :] *= -1
|
||||
|
||||
name = Path(f"./images/{im_data.name}")
|
||||
name = filename_map[im_data.name]
|
||||
name = Path(f"./images/{name}")
|
||||
|
||||
frame = {
|
||||
"file_path": name.as_posix(),
|
||||
|
||||
@@ -46,6 +46,19 @@ CAMERA_MODELS = {
|
||||
}
|
||||
|
||||
|
||||
def list_images(data: Path) -> List[Path]:
|
||||
"""Lists all supported images in a directory
|
||||
|
||||
Args:
|
||||
data: Path to the directory of images.
|
||||
Returns:
|
||||
Paths to images contained in the directory
|
||||
"""
|
||||
allowed_exts = [".jpg", ".jpeg", ".png", ".tif", ".tiff"]
|
||||
image_paths = sorted([p for p in data.glob("[!.]*") if p.suffix.lower() in allowed_exts])
|
||||
return image_paths
|
||||
|
||||
|
||||
def get_image_filenames(directory: Path, max_num_images: int = -1) -> Tuple[List[Path], int]:
|
||||
"""Returns a list of image filenames in a directory.
|
||||
|
||||
@@ -55,8 +68,7 @@ def get_image_filenames(directory: Path, max_num_images: int = -1) -> Tuple[List
|
||||
Returns:
|
||||
A tuple of A list of image filenames, number of original image paths.
|
||||
"""
|
||||
allowed_exts = [".jpg", ".jpeg", ".png", ".tif", ".tiff"]
|
||||
image_paths = sorted([p for p in directory.glob("[!.]*") if p.suffix.lower() in allowed_exts])
|
||||
image_paths = list_images(directory)
|
||||
num_orig_images = len(image_paths)
|
||||
|
||||
if max_num_images != -1 and num_orig_images > max_num_images:
|
||||
@@ -240,8 +252,7 @@ def copy_images(data: Path, image_dir: Path, verbose) -> int:
|
||||
The number of images copied.
|
||||
"""
|
||||
with status(msg="[bold yellow]Copying images...", spinner="bouncingBall", verbose=verbose):
|
||||
allowed_exts = [".jpg", ".jpeg", ".png", ".tif", ".tiff"]
|
||||
image_paths = sorted([p for p in data.glob("[!.]*") if p.suffix.lower() in allowed_exts])
|
||||
image_paths = list_images(data)
|
||||
|
||||
if len(image_paths) == 0:
|
||||
CONSOLE.log("[bold red]:skull: No usable images in the data folder.")
|
||||
|
||||
Reference in new issue
Block a user