Skip to content

Recipes#

capturegraph-recipes is CaptureGraph's analysis package: structure from motion, learned depth and 3D Gaussian splats from captured images, and the scheduling library that decides when and where the next capture is worth taking. One import is the whole surface, and the reconstruction half reads as a pipeline:

import capturegraph_recipes as cgr

frames = cgr.splats.scene_dataset(session.capture)  # a cg.SceneCapture's keyframes as posed images
pairs = cgr.sfm.nearby_pairs(frames.pose)  # frames.pose: the frames' poses as one array
model = cgr.sfm.triangulate(frames, cgr.sfm.tracks(frames.image, pairs))
frames = cgr.sfm.reposed(frames, model)  # each frame moved to the pose the model solved for it
splat = cgr.splats.train(frames, cgr.splats.depth_seed(frames))  # seeded from the frames' captured depth

The package has two halves, and they use the scratch differently. The reconstruction stages — cgr.sfm, cgr.depth, cgr.splats — are cg.pure_functions: memoized on their arguments, so a growing dataset recomputes only what is new, and every one of them logs what it found, so a page's build log reads as the record of what happened to its photographs. The scheduling stages are plain functions — a server interceptor wraps them in a cg.pure_function of its own — and its reservation books are cg.ImpureState, the scratch's locked, persistent state; only notification_candidates, the selection a server offers, is memoized by the package itself.

The package sits above the core and ui packages and beneath the server. It is also the worked example of four of the five extension points — the hooks the core exposes so a package above it can add a type, a component, a recipe or a package — adding its types, its viewer and its scheduler without editing the core. The fifth, a log sink, is cgui.Notebook in the ui package.

Install#

The package is a member of the monorepo's uv workspace, so uv sync from a clone installs it. CaptureGraph is not published to PyPI: a project of your own depends on the package from a clone, and the same clone supplies capturegraph-lib and capturegraph-ui, which it depends on:

uv add --editable /path/to/CaptureGraph/capturegraph-recipes

It carries the heavy analysis dependencies — SciPy, OpenCV, Hugging Face Hub, meteostat and the weather clients — so a study that only defines procedures never installs them.

The GPU interpreter#

Three stages need a GPU: cgr.depth.predict, a monocular model's depth for each image on its own; cgr.depth.multiview, a multi-view model's cameras, points and depths for a set of images posed together in one forward pass; and cgr.splats.train. They run in a separate interpreter holding torch and the model packages; the package's own environment never imports torch. The interpreter is the one the CG_GPU_PYTHON environment variable names, else the one the ns-train on the path belongs to:

export CG_GPU_PYTHON=/path/to/gpu-env/bin/python

The package exports the variable's name as cgr.GPU_PYTHON_ENV, a string, so a script or an error message need not spell it; there is no Python-side override. A depth model runs there as a driver: a capturegraph-free script the library runs by path with --images, --weights and --output directories, the contract Reconstruction spells out. That interpreter needs nerfstudio (torch, gsplat) for train, depth-anything-3 for cgr.depth.DA3_LARGE and Pi3's pi3 package for cgr.depth.PI3X; a model of your own needs whatever its driver imports. The GPU stages serialise on cg.lock("gpu"), so two of them never share the card.

What it adds#

Folder Holds
cgr.sfm Structure from motion: keypoints, pairs, matches, tracks, triangulation, bundle adjustment, incremental reconstruction, and the alignment of a model onto its priors — EXIF fixes, ARKit poses, the ground plane.
cgr.depth Learned depth: models run as drivers in the GPU interpreter, their predictions fitted to measured depth.
cgr.splats 3D Gaussian splats: datasets from scene captures, videos and panoramas, seeds, and training under nerfstudio; cgr.SplatViewer draws the result on a page, with its JavaScript shipped by this package.
cgr.scheduling Distribution-aware capture scheduling: distance and energy metrics, forecasting, Void & Cluster session selection — each pick fills the largest gap in coverage, and a pick that later becomes crowded is released and re-placed — reservation books, and notification_candidates, the capture times a server interceptor offers the app as its next reminder.

The ten types at the cgr root are the vocabulary the recipes need beyond the core's: what a sparse reconstruction stores, and what a splat and a learned depth are stored as. A value a phone can capture is already a core type, so all ten are analysis-only — analysis_only = True, and @cg.procedure rejects a schema holding one — which is why they have no iOS mirror and no place in a schema. (cgr.depth keeps its Model, Driver and Weights under its own name, and cgr.scheduling its books.)

Type What it is
cgr.Reconstruction A sparse model: solved cameras, the points they see, and which keypoint saw which.
cgr.PosedImage A frame a reconstruction works from: an image, the pose that took it with intrinsics at the image's own size, and its depth or Missing.
cgr.Multiview What one forward pass of a multi-view network yields: a scale-free Reconstruction and one RelativeDepth per image.
cgr.Keypoints The local features found in one image.
cgr.Pairs Which images of an array to compare.
cgr.Matches The keypoints two images agree on.
cgr.Tracks Keypoints chained across images into tracks.
cgr.Observations Which keypoint of which image saw which point.
cgr.RelativeDepth A learned model's depth map in the model's own units, metric only up to an affine map in inverse depth.
cgr.Splat A 3D Gaussian splat model as a PLY file.

Section contents#

From photographs to a splat: cgr.sfm, cgr.depth, cgr.splats, stage by stage

Distance functions, distribution-aware session selection, and per-user reservations