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