def export_points_reconstruction()

in opensfm/actions/export_colmap.py [0:0]


def export_points_reconstruction(data, path, images_map, binary: bool=False):
    reconstructions = data.load_reconstruction()
    tracks_manager = data.load_tracks_manager()

    points_map = {}

    if binary:
        fout = data.io_handler.open(os.path.join(path, "points3D.bin"), "wb")
        n_points = 0
        for reconstruction in reconstructions:
            n_points += len(reconstruction.points)
        fout.write(pack("<Q", n_points))
    else:
        fout = data.io_handler.open_wt(os.path.join(path, "points3D.txt"))

    i = 0
    for reconstruction in reconstructions:
        for point in reconstruction.points.values():
            c = point.coordinates
            cl = point.color
            format_line = "%d %f %f %f %d %d %d %f "
            format_tuple = [
                int(i),
                c[0],
                c[1],
                c[2],
                int(cl[0]),
                int(cl[1]),
                int(cl[2]),
                0.0,
            ]

            if binary:
                fout.write(pack("<Q", int(i)))
                fout.write(pack("<3d", c[0], c[1], c[2]))  # Position
                fout.write(pack("<3B", *[int(i) for i in cl]))  # Color
                fout.write(pack("<d", 0.0))  # Error

            track_tuple = []
            for image, obs in tracks_manager.get_track_observations(point.id).items():
                if image not in reconstruction.shots:
                    continue
                format_line += "%d %d "
                track_tuple += [images_map[image], obs.id]
            format_line += "\n"

            if binary:
                fout.write(pack("<Q", len(track_tuple) // 2))  # Track length
                for el in track_tuple:
                    fout.write(pack("<i", el))  # Track
            else:
                fout.write(format_line % tuple(format_tuple + track_tuple))
            points_map[point.id] = i
            i += 1
    fout.close()
    return points_map