MCPcopy
hub / github.com/cvg/Hierarchical-Localization / write_images_text

Function write_images_text

hloc/utils/read_write_model.py:262–287  ·  view source on GitHub ↗

see: src/base/reconstruction.cc void Reconstruction::ReadImagesText(const std::string& path) void Reconstruction::WriteImagesText(const std::string& path)

(images, path)

Source from the content-addressed store, hash-verified

260
261
262def write_images_text(images, path):
263 """
264 see: src/base/reconstruction.cc
265 void Reconstruction::ReadImagesText(const std::string& path)
266 void Reconstruction::WriteImagesText(const std::string& path)
267 """
268 if len(images) == 0:
269 mean_observations = 0
270 else:
271 mean_observations = sum((len(img.point3D_ids) for _, img in images.items()))/len(images)
272 HEADER = "# Image list with two lines of data per image:\n" + \
273 "# IMAGE_ID, QW, QX, QY, QZ, TX, TY, TZ, CAMERA_ID, NAME\n" + \
274 "# POINTS2D[] as (X, Y, POINT3D_ID)\n" + \
275 "# Number of images: {}, mean observations per image: {}\n".format(len(images), mean_observations)
276
277 with open(path, "w") as fid:
278 fid.write(HEADER)
279 for _, img in images.items():
280 image_header = [img.id, *img.qvec, *img.tvec, img.camera_id, img.name]
281 first_line = " ".join(map(str, image_header))
282 fid.write(first_line + "\n")
283
284 points_strings = []
285 for xy, point3D_id in zip(img.xys, img.point3D_ids):
286 points_strings.append(" ".join(map(str, [*xy, point3D_id])))
287 fid.write(" ".join(points_strings) + "\n")
288
289
290def write_images_binary(images, path_to_model_file):

Callers 1

write_modelFunction · 0.85

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected