COLMAP sparse models
Load the three binary files from one COLMAP sparse reconstruction. Select the loader explicitly and pass the URL of cameras.bin. The loader fetches images.bin and points3D.bin from the same directory. Image names are relative to the capture's separate image directory.
import {load} from '@loaders.gl/core';
import {COLMAPLoader} from '@loaders.gl/scene/colmap';
const {cameras, images, points3D} = await load('/capture/sparse/0/cameras.bin', COLMAPLoader);
for (const image of images.values()) {
const camera = cameras.get(image.cameraId)!;
console.log(image.name, camera.model, camera.parameters);
}
For local file selections, import parseCOLMAPSparseModel from @loaders.gl/scene/colmap/bundled and pass an object containing the three ArrayBuffer values keyed by cameras, images and points3D. The loader reads the registered per-image poses from both classic and rig-aware reconstructions. Rig assignments and frame metadata are outside this three-file interface.
Camera parameters retain COLMAP model order, including distortion coefficients. Image quaternions use WXYZ order and map world coordinates to camera coordinates with the recorded translation. The camera axes point right, down and forward. Pixel coordinates are interleaved XY pairs in imagePoints. The corresponding point3DIds are unsigned 64-bit integers. Compare against COLMAP_INVALID_POINT3D_ID to identify observations without a 3D match. Sparse point maps use bigint keys. Each point carries XYZ, RGB, mean reprojection error, and an interleaved track of image IDs and zero-based observation indices.
To check an undistorted PINHOLE or SIMPLE_PINHOLE capture after building the repository, run node modules/scene/scripts/colmap/verify-reprojection.mjs /path/to/sparse/0. The script checks track identities in both directions and reports the pixel residual distribution over all linked observations. The COLMAP format reference describes the source conventions.
For a reproducible example, use the three files from the Mip-NeRF 360 Bonsai sparse model. Across 292 images and 206,613 points, its 1,795,457 linked observations give a median residual of 0.729 pixels and a 95th percentile of 2.341 pixels.
Fetch training photographs on demand
A sparse reconstruction contains image paths and camera parameters. The image directory can be hosted separately. Open the reconstruction once and request each photograph by its registered ID.
import {load} from '@loaders.gl/core';
import {COLMAPSource} from '@loaders.gl/scene/colmap/source';
const source = await COLMAPSource.open('/capture/sparse/0/cameras.bin', {
imageBaseUrl: '/capture/images/'
}, {load});
const image = source.model.images.values().next().value;
if (image) {
const camera = source.model.cameras.get(image.cameraId);
const bitmap = await source.loadImage(image.id);
try {
// Use bitmap, camera calibration, and image pose as a training view.
} finally {
bitmap.close();
}
}
Use getImageURL(id) to resolve a photo path or fetchImage(id, {signal}) to obtain its original
bytes. In a browser or worker, loadImage(id, {signal}) decodes a bitmap at the original resolution
without applying EXIF orientation. Match the bitmap dimensions to the recorded camera dimensions
before training. Set imageFetch for separate photograph credentials and modelOptions for the
model requests.