Skip to content

incremental

incremental #

reconstruct — a model from images and tracks alone, grown one image at a time.

  1. Priors. Every image gets a pinhole guess (growing.load): the focal length from its EXIF 35 mm equivalent, else FOCAL_PRIOR times its longer side, and the principal point at its centre. Nothing else is known.
  2. Seed. Among the pairs sharing the most tracks, the first whose essential-matrix pose triangulates them with a median angle of at least MIN_SEED_ANGLE_DEGREES starts the model: its first camera at the origin, its second a unit baseline away, so the model's scale is arbitrary until aligned or a bundle adjustment with priors fixes it.
  3. Growth. The unregistered image that sees the most placed points is registered by PnP RANSAC, its unplaced tracks are triangulated, and a local adjustment refines that camera against its points. Whenever the point count has grown GLOBAL_GROWTH-fold since the last one, a global adjustment refines every camera, point and intrinsic, and points that no longer pass the triangulation checks are dropped. Registration ends when no image sees MIN_PNP_POINTS placed points.

reconstruct(images, tracks) #

The sparse model tracks imply, with no pose or calibration known in advance.

The result's cameras carry the solved intrinsics at each image's size, keyed by image index; an image the growth could not register is absent. Its scale is arbitrary: lock it with aligned against prior poses, or with bundle_adjust given a position sigma once priors exist.

Parameters:

Name Type Description Default
images Array[Image]

The images the tracks index.

required
tracks Tracks

The tracks of images.

required
Source code in capturegraph-recipes/capturegraph_recipes/sfm/reconstruction/incremental.py
@cg.pure_function("sfm.reconstruct/1")
def reconstruct(images: cg.Array[cg.Image], tracks: Tracks) -> Reconstruction:
    """The sparse model ``tracks`` imply, with no pose or calibration known in advance.

    The result's cameras carry the solved intrinsics at each image's size,
    keyed by image index; an image the growth could not register is absent.
    Its scale is arbitrary: lock it with ``aligned`` against prior poses, or
    with ``bundle_adjust`` given a position sigma once priors exist.

    Args:
        images: The images the tracks index.
        tracks: The tracks of ``images``.
    """
    model = load(images, tracks)
    _seed(model)
    placed_at_last_global = len(model.points)
    failed: set[int] = set()
    with cg.logging.progress(total=len(images), label="Registering images") as count:
        for image in model.registered():
            with count.turn():
                _report(model, image, count, reprojection_px=0.0)
        while True:
            image = _next_image(model, failed)
            if image is None:
                break
            with count.turn():
                if not _register(model, image):
                    failed.add(image)
                    cg.logging.warning("Could not register image", image=image)
                    continue
                stats = _adjust_locally(model, image)
                if len(model.points) >= GLOBAL_GROWTH * placed_at_last_global:
                    stats = _adjust_globally(model)
                    placed_at_last_global = len(model.points)
                _report(model, image, count, reprojection_px=stats["reprojection_after_px"])
    stats = _adjust_globally(model)
    cg.logging.info(
        "Reconstructed",
        registered=len(model.registered()),
        unregistered=len(images) - len(model.registered()),
        points=len(model.points),
        reprojection_px=stats["reprojection_after_px"],
    )
    return sealed(model)