see: src/base/reconstruction.cc void Reconstruction::ReadPoints3DText(const std::string& path) void Reconstruction::WritePoints3DText(const std::string& path)
(points3D, path)
| 363 | |
| 364 | |
| 365 | def write_points3D_text(points3D, path): |
| 366 | """ |
| 367 | see: src/base/reconstruction.cc |
| 368 | void Reconstruction::ReadPoints3DText(const std::string& path) |
| 369 | void Reconstruction::WritePoints3DText(const std::string& path) |
| 370 | """ |
| 371 | if len(points3D) == 0: |
| 372 | mean_track_length = 0 |
| 373 | else: |
| 374 | mean_track_length = sum((len(pt.image_ids) for _, pt in points3D.items()))/len(points3D) |
| 375 | HEADER = "# 3D point list with one line of data per point:\n" + \ |
| 376 | "# POINT3D_ID, X, Y, Z, R, G, B, ERROR, TRACK[] as (IMAGE_ID, POINT2D_IDX)\n" + \ |
| 377 | "# Number of points: {}, mean track length: {}\n".format(len(points3D), mean_track_length) |
| 378 | |
| 379 | with open(path, "w") as fid: |
| 380 | fid.write(HEADER) |
| 381 | for _, pt in points3D.items(): |
| 382 | point_header = [pt.id, *pt.xyz, *pt.rgb, pt.error] |
| 383 | fid.write(" ".join(map(str, point_header)) + " ") |
| 384 | track_strings = [] |
| 385 | for image_id, point2D in zip(pt.image_ids, pt.point2D_idxs): |
| 386 | track_strings.append(" ".join(map(str, [image_id, point2D]))) |
| 387 | fid.write(" ".join(track_strings) + "\n") |
| 388 | |
| 389 | |
| 390 | def write_points3D_binary(points3D, path_to_model_file): |