Skip to main content

@luma.gl/graph/gpu-sfm

reconstructImagePair(device, width, height, views) estimates relative camera pose and sparse scene geometry from two overlapping, undistorted images with known intrinsics. Pass an ordered pair of objects with an imageId, row-major grayscale Float32Array in [0, 1], and pixel intrinsics [fx, fy, cx, cy].

The returned SparseReconstruction contains cameras and points with their image observations. Coordinates use the first camera as the world frame and one unit between camera centers. matchImagePair exposes the WebGPU matching stage; estimateTwoViewReconstruction accepts correspondences directly for CPU pose recovery and triangulation.

Pass {pyramidLevels: 3, maxDisplacementPixels: 96} as the last argument to matchImagePair or reconstructImagePair to compare binary descriptors across power-of-two image scales. Each direction searches the cells inside a square displacement window measured in original-image pixels. Set the bound from the expected motion. Features outside the window cannot match. Pixel coordinates and camera intrinsics stay in the original image frame. The default is single-level exhaustive matching.

Train Gaussian splats from a reconstruction

Evaluating a registered image pair​

Serve the three binary COLMAP files and two corresponding undistorted, full-frame photographs over HTTP with browser CORS access. Set VITE_SFM_CAPTURE to the capture URLs, two numeric registered image IDs and the desired evaluation resolution. Run the optional benchmark from the repository root.

VITE_SFM_CAPTURE='{"camerasUrl":"http://localhost:8000/sparse/0/cameras.bin","imageBaseUrl":"http://localhost:8000/images","imageIds":[1,3],"width":640,"height":426}' LUMA_TEST_BROWSER_BENCHMARKS=true yarn test-headless --reporter=verbose modules/graph/test/gpu-sfm/capture-benchmark.spec.ts

The report includes mutual match and triangulated landmark counts, rotation and baseline-direction error against the calibrated poses, median reprojection error in resized pixels, and elapsed matching and solving times. Matching time includes GPU submission and readback. Only pixels and intrinsics enter the estimator. The benchmark also exercises the unobservable same-view case. Keep external capture data outside the repository.

Registering more cameras​

reconstructImages(device, width, height, views, options) matches candidate pairs on the GPU. Each view supplies a unique image ID, pinhole intrinsics and a row-major grayscale raster. By default it tries every pair. Pass imagePairs as pairs of indices into views to restrict matching to overlapping photographs. estimateMultiViewReconstruction(cameras, pairs, pixelTolerance) accepts precomputed correspondences in original pixel coordinates. A detector must identify a feature at the same coordinates in every pair involving its image.

The CPU solver seeds the scene from the verified pair with the most triangulated points, joins consistent observations into tracks, and registers additional cameras with calibrated six-point RANSAC. New registered views triangulate landmarks for later cameras. The seed baseline defines the world unit. unregisteredImageIds identifies images outside the recovered component or lacking sufficient noncoplanar support. Supply five or more registered IDs to the capture benchmark to report trajectory errors after alignment to the first seed camera and its baseline.

The sequence benchmark expects every supplied view to register. Set minimumRegistered for a capture with deliberately disconnected views.

Local bundle adjustment​

Pass a connected reconstruction window to refineSparseReconstruction(scene, options) to refine camera poses and landmarks jointly using a Huber pixel loss. The first pose and the distance between the first two camera centers fix the reconstruction frame and scale. Intrinsics and measured observations stay fixed. The result contains the refined reconstruction, initial and final robust costs, and the number of accepted steps.

await refineSparseReconstructionOnGPU(device, scene, options) evaluates per-observation projections and Jacobians in parallel with a WebGPU command graph. Each iteration reads those derivatives back to solve the reduced camera system on the CPU. Supply a local window because the reduced matrix grows quadratically with the camera count. The capture benchmark reports costs, camera errors, and elapsed refinement time on the same input tracks.