Skip to content

priors

priors #

exif_priors — the poses a burst's EXIF implies: GPS fixes placed and headed at a site.

FULL_FRAME_WIDTH_MM = 36.0 module-attribute #

The sensor width a 35 mm-equivalent focal length is quoted against.

exif_priors(images, anchor) #

A prior pose for every image whose EXIF holds a GPS fix, keyed by array position.

Keyed like a reconstruction's cameras, so a sparse map of priors and a model line up. The fix places the camera at its tangent-plane offset from anchor (x north, y up, z east); a compass heading, when the fix carries one, yaws the camera to look along it, else it looks along -z; the 35 mm equivalent focal length, when present, gives pinhole intrinsics centred at the stored image's size. An image without a fix has no key, so it chains as Missing.

Parameters:

Name Type Description Default
images Array[Image]

The photographs.

required
anchor Location

The location the world's origin sits at, shared by every burst that should land in one world.

required
Source code in capturegraph-recipes/capturegraph_recipes/sfm/alignment/priors.py
@cg.pure_function("sfm.exif_priors/1")
def exif_priors(images: cg.Array[cg.Image], anchor: cg.Location) -> cg.Map[cg.String, cg.Pose]:
    """A prior pose for every image whose EXIF holds a GPS fix, keyed by array position.

    Keyed like a reconstruction's cameras, so a sparse map of priors and a
    model line up. The fix places the camera at its tangent-plane offset from ``anchor``
    (x north, y up, z east); a compass heading, when the fix carries one,
    yaws the camera to look along it, else it looks along ``-z``; the 35 mm
    equivalent focal length, when present, gives pinhole intrinsics centred
    at the stored image's size. An image without a fix has no key, so it
    chains as ``Missing``.

    Args:
        images: The photographs.
        anchor: The location the world's origin sits at, shared by every
            burst that should land in one world.
    """
    priors: dict[str, cg.Pose] = {}
    headings = 0
    for index, image in enumerate(cg.logging.progress(images, label="Reading EXIF")):
        exif = image.exif()
        gps = exif.gps
        if gps is None or gps.latitude is None or gps.longitude is None:
            continue
        fix = cg.Location(
            latitude=gps.latitude,
            longitude=gps.longitude,
            altitude_meters=gps.altitude if gps.altitude is not None else anchor.altitude_meters,
        )
        headings += gps.img_direction is not None
        with image.pil() as picture:
            width, height = picture.size
        priors[camera_key(index)] = pose_from_matrix(
            _camera_to_world(local_offset(fix, anchor), gps.img_direction),
            _template(exif, width, height),
        )
    cg.logging.info("Read EXIF priors", fixes=len(priors), images=len(images), headings=headings)
    return cg.Map[cg.String, cg.Pose](priors)