I/O Utilities¶
Python bindings for src/theia/io: reconstruction import/export, Bundler/NVM/COLMAP-style writers, and NeRF/SDF studio JSON. All symbols below live on pytheia.io (submodule defined in io.cc).
Convention: read helpers exposed from io_wrapper.h return a leading bool success flag, then loaded objects. Write functions return bool directly (except where noted).
Classes¶
BundlerObservation¶
One 2D observation of a Bundler 3D point: camera_index, feature_index, x, y.
BundlerPoint¶
Bundler 3D point: position, color, view_list (list of BundlerObservation).
BundlerFileReader(lists_file, bundle_file)¶
Low-level Bundler parser: call ParseListsFile() / ParseBundleFile() then inspect cameras(), points(), img_entries().
BundlerCamera¶
Fields: translation, rotation, focal_length, radial_coeff_1, radial_coeff_2.
ListImgEntry¶
List-file row: filename, second_entry, focal_length.
Reading / importing¶
| Function | Returns | Description |
|---|---|---|
ReadReconstruction(input_file) |
(ok, reconstruction) |
Binary Theia reconstruction (reconstruction_reader.h). |
ReadBundlerFiles(lists_file, bundle_file) |
(ok, reconstruction) |
Noah Snavely Bundler lists + bundle. |
ImportNVMFile(nvm_filepath) |
(ok, reconstruction) |
NVM_V3 text bundle (.nvm). |
Read1DSFM(dataset_directory) |
(ok, reconstruction, view_graph) |
1DSfM layout: sparse geometry + view graph. |
ReadStrechaDataset(dataset_directory) |
(ok, reconstruction) |
Strecha multi-view benchmark style data. |
PopulateImageSizesAndPrincipalPoints(image_directory) |
(ok, reconstruction) |
Wrapper around populate_image_sizes.h: loads image files named by each view and sets camera size and center principal point. The Python binding passes a fresh empty Reconstruction into the C++ call (see io_wrapper.cc); it succeeds trivially if there are no views. After ReadBundlerFiles, you typically need image dimensions filled on that same reconstruction—use C++ or extend the binding if the empty-reconstruction path is insufficient. |
Writing reconstructions and exchange formats¶
| Function | Returns | Description |
|---|---|---|
WriteReconstruction(reconstruction, output_file, write_full_reconstruction=False) |
bool |
Binary Theia format (reconstruction_writer.h). By default only estimated views and multi-view tracks are written; pass write_full_reconstruction=True for the complete model. |
WriteReconstructionJson(reconstruction, output_json_file) |
bool |
JSON export of estimated views and tracks. |
WritePlyFile(ply_file, reconstruction, camera_color, min_num_observations_per_point) |
bool |
PLY point cloud for MeshLab-style viewers (write_ply_file.h). camera_color is an Eigen::Vector3i (RGB); use a NumPy length-3 integer array from Python. |
WriteRigPlyFile(ply_file, reconstruction, sensor_color, min_num_observations_per_point=2, …) |
bool |
Rig-aware PLY: tracks + capture body centers + sensor centers + densely sampled trajectory and intra-capture baseline polylines (MeshLab / Open3D). Optional capture_color, trajectory_color, baseline_color, edge_samples. |
WriteBundlerFiles(reconstruction, lists_file, bundle_file) |
bool |
Bundler lists + bundle from a reconstruction. |
WriteNVMFile(nvm_filepath, reconstruction) |
bool |
NVM text. |
WriteColmapFiles(reconstruction, output_directory, binary=False) |
bool |
COLMAP files under output_directory: text (cameras.txt, images.txt, points3D.txt) by default, or the COLMAP binary model (cameras.bin, images.bin, points3D.bin, little-endian) with binary=True. |
WriteTransformsJson(path_to_images, reconstruction, out_json_file) |
bool |
transforms.json for instant-ngp, gsplat and Nerfstudio. transform_matrix is camera-to-world in OpenGL axes (y and z flipped relative to OpenCV). See Gaussian splatting export. |
WriteNerfStudio(path_to_images, reconstruction, aabb_scale, out_json_file) |
bool |
transforms.json-style export (PINHOLE / FISHEYE mapping per write_nerfstudio.h). |
WriteSdfStudio(path_to_images, reconstruction, nearfar, radius) |
bool |
SDFStudio JSON; PINHOLE, undistorted images (write_sdfstudio.h). nearfar is (near, far) floats. |
Binary .recon format (compact)¶
ReadReconstruction / WriteReconstruction use a cereal PortableBinaryArchive. Since
Reconstruction format version 2 (pyTheia 1.3.0) the file is written in a compact layout:
- Each observation is stored once (in the view's
TrackId -> Featuremap). The inverseFeature -> TrackIdmap is rebuilt on load instead of being written. - A
Featureis a flags byte plus its coordinates. Coordinates are stored asfloat32when that is exact, otherwise asfloat64. The default covariance (identity) and depth prior (0, variance 1) are omitted. Track::view_ids_is not written. It is rebuilt from the views on load.
Roughly 13 bytes per observation for the feature data, instead of about 190 bytes before. The format is lossless. Files written by older builds (Reconstruction version 0 or 1) still load exactly, because each class keeps its legacy code path for the old class versions. Files written by the new build cannot be read by pyTheia 1.2.x.
Export to Nerfstudio¶
Writes a transforms.json compatible with Nerfstudio.
import pytheia as pt
ok = pt.io.WriteNerfStudio("/path/to/images", recon, 16, "/path/to/out/transforms.json")
# aabb_scale is typically 2, 4, 8, or 16
Notes: Supported camera models are mapped internally (PINHOLE and FISHEYE). Images are referenced as path_to_images/view_image_name.
Export to SDFStudio¶
Writes JSON compatible with SDFStudio. Images must be undistorted and PINHOLE.
import pytheia as pt
ok = pt.io.WriteSdfStudio("/path/to/images", recon, (2.0, 6.0), 1.0)
# nearfar is (near, far); radius controls scene radius
Not exposed in Python¶
The C++ tree also includes helpers such as WriteMatchesAndGeometry and WriteCalibration (write_matches.h, write_calibration.h) without pybind entries in io.cc. Use the C++ API or extend the bindings if you need those.