see: src/colmap/scene/reconstruction.cc void Reconstruction::ReadPoints3DText(const std::string& path) void Reconstruction::WritePoints3DText(const std::string& path)
(points3D, path)
| 425 | |
| 426 | |
| 427 | def write_points3D_text(points3D, path): |
| 428 | """ |
| 429 | see: src/colmap/scene/reconstruction.cc |
| 430 | void Reconstruction::ReadPoints3DText(const std::string& path) |
| 431 | void Reconstruction::WritePoints3DText(const std::string& path) |
| 432 | """ |
| 433 | if len(points3D) == 0: |
| 434 | mean_track_length = 0 |
| 435 | else: |
| 436 | mean_track_length = sum( |
| 437 | (len(pt.image_ids) for _, pt in points3D.items()) |
| 438 | ) / len(points3D) |
| 439 | HEADER = ( |
| 440 | "# 3D point list with one line of data per point:\n" |
| 441 | + "# POINT3D_ID, X, Y, Z, R, G, B, ERROR, TRACK[] as (IMAGE_ID, POINT2D_IDX)\n" |
| 442 | + "# Number of points: {}, mean track length: {}\n".format( |
| 443 | len(points3D), mean_track_length |
| 444 | ) |
| 445 | ) |
| 446 | |
| 447 | with open(path, "w") as fid: |
| 448 | fid.write(HEADER) |
| 449 | for _, pt in points3D.items(): |
| 450 | point_header = [pt.id, *pt.xyz, *pt.rgb, pt.error] |
| 451 | fid.write(" ".join(map(str, point_header)) + " ") |
| 452 | track_strings = [] |
| 453 | for image_id, point2D in zip(pt.image_ids, pt.point2D_idxs): |
| 454 | track_strings.append(" ".join(map(str, [image_id, point2D]))) |
| 455 | fid.write(" ".join(track_strings) + "\n") |
| 456 | |
| 457 | |
| 458 | def write_points3D_binary(points3D, path_to_model_file): |