From 2f91cb7ad972fc76bfb24bd298820fb8901255bd Mon Sep 17 00:00:00 2001 From: Sasha Mitchell Date: Mon, 28 Sep 2026 17:33:46 +0700 Subject: [PATCH] Keep spaces in a COLMAP image name read_images_text kept only the first word, so "my photo.jpg" came back as "my". --- nerfstudio/data/utils/colmap_parsing_utils.py | 5 +++- tests/data/test_colmap_image_name.py | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/data/test_colmap_image_name.py diff --git a/nerfstudio/data/utils/colmap_parsing_utils.py b/nerfstudio/data/utils/colmap_parsing_utils.py index 0eeaf6911b..4d7ca33d5e 100644 --- a/nerfstudio/data/utils/colmap_parsing_utils.py +++ b/nerfstudio/data/utils/colmap_parsing_utils.py @@ -204,7 +204,10 @@ def read_images_text(path): qvec = np.array(tuple(map(float, elems[1:5]))) tvec = np.array(tuple(map(float, elems[5:8]))) camera_id = int(elems[8]) - image_name = elems[9] + # COLMAP writes the image name as the rest of the line, so a space stays in the name. + if len(elems) < 10: + raise IndexError("COLMAP image line is missing the name") + image_name = " ".join(elems[9:]) elems = fid.readline().split() xys = np.column_stack([tuple(map(float, elems[0::3])), tuple(map(float, elems[1::3]))]) point3D_ids = np.array(tuple(map(int, elems[2::3]))) diff --git a/tests/data/test_colmap_image_name.py b/tests/data/test_colmap_image_name.py new file mode 100644 index 0000000000..7269cd890c --- /dev/null +++ b/tests/data/test_colmap_image_name.py @@ -0,0 +1,29 @@ +"""COLMAP images.txt names can contain spaces.""" + +from pathlib import Path + +from nerfstudio.data.utils.colmap_parsing_utils import read_images_text + + +def test_image_name_keeps_spaces(tmp_path: Path): + images_txt = tmp_path / "images.txt" + images_txt.write_text( + "\n".join( + [ + "# Image list with two lines of data per image:", + "1 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1 my photo.jpg", + "1.5 2.5 7", + "2 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1 plain.jpg", + "0.0 0.0 -1", + "", + ] + ) + ) + + images = read_images_text(images_txt) + + assert images[1].name == "my photo.jpg" + assert images[1].point3D_ids.tolist() == [7] + assert images[1].xys.tolist() == [[1.5, 2.5]] + assert images[2].name == "plain.jpg" + assert images[2].point3D_ids.tolist() == [-1]