Skip to content

Commit f32e0e4

Browse files
committed
fix bugs in COLMAP images text loading
1 parent 9c45032 commit f32e0e4

File tree

1 file changed

+21
-35
lines changed

1 file changed

+21
-35
lines changed

fvdb_reality_capture/sfm_scene/_colmap_utils/scene_manager.py

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -184,42 +184,28 @@ def _load_images_bin(self, input_file):
184184
def _load_images_txt(self, input_file):
185185
self.images = OrderedDict()
186186

187-
with open(input_file, "r") as f:
188-
is_camera_description_line = False
189-
190-
for line in iter(lambda: f.readline().strip(), ""):
191-
if not line or line.startswith("#"):
192-
continue
193-
194-
is_camera_description_line = not is_camera_description_line
195-
196-
data = line.split()
197-
198-
if is_camera_description_line:
199-
read_quat = np.array(list(map(float, data[1:5])))
200-
read_pos = np.array(list(map(float, data[5:8])))
201-
image_id = int(data[0])
202-
image = Image(
203-
data[-1],
204-
int(data[-2]),
205-
Quaternion(read_quat),
206-
read_pos,
187+
with open(input_file, "r") as fid:
188+
while True:
189+
line = fid.readline()
190+
if not line:
191+
break
192+
line = line.strip()
193+
if len(line) > 0 and line[0] != "#":
194+
elems = line.split()
195+
image_id = int(elems[0])
196+
qvec = np.array(list(map(float, elems[1:5])))
197+
tvec = np.array(list(map(float, elems[5:8])))
198+
camera_id = int(elems[8])
199+
image_name = elems[9]
200+
elems = fid.readline().split()
201+
xys = np.column_stack([tuple(map(float, elems[0::3])),
202+
tuple(map(float, elems[1::3]))])
203+
point3D_ids = np.array(tuple(map(int, elems[2::3])))
204+
self.images[image_id] = Image(
205+
image_name, camera_id, Quaternion(qvec), tvec
207206
)
208-
else:
209-
points_2d_x = [float(x) for x in data[::3]]
210-
points_2d_y = [float(y) for y in data[1::3]]
211-
point3d_ids = [np.uint64(pid) for pid in data[2::3]]
212-
image.points2D = np.array([points_2d_x, points_2d_y]).T
213-
image.point3D_ids = np.array(point3d_ids, dtype=np.uint64)
214-
215-
# automatically remove points without an associated 3D point
216-
# mask = (image.point3D_ids != SceneManager.INVALID_POINT3D)
217-
# image.points2D = image.points2D[mask]
218-
# image.point3D_ids = image.point3D_ids[mask]
219-
220-
self.images[image_id] = image
221-
self.name_to_image_id[image.name] = image_id
222-
207+
self.images[image_id].points2D = xys
208+
self.images[image_id].point3D_ids = point3D_ids
223209
self.last_image_id = max(self.last_image_id, image_id)
224210

225211
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)