geotrax.utils.registration¶
Homography estimation between two images through a Stabilo Stabilizer: the single implementation behind georeferencing (frame to master frame, master frame to orthophoto) and the analysis tools. Feature detection, matching and the robust fit are delegated to Stabilo, so every detector it supports is available here; the Feature detectors guide compares them.
Registration¶
estimate_homography
¶
estimate_homography(img_src: ndarray, img_dst: ndarray, logger: Logger, **stabilizer_kwargs: Any) -> tuple
Estimate the homography that maps source image coordinates to destination coordinates.
The destination is the Stabilizer's reference frame and the source its current frame, so the
RANSAC reprojection threshold is evaluated in destination coordinates. If detection or matching
fails, max_features is halved and the registration retried, down to
MIN_MAX_FEATURES; the detector-free loftr
ignores max_features and is not retried.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_src
|
ndarray
|
Source image, e.g. a video frame. |
required |
img_dst
|
ndarray
|
Destination image, e.g. an orthophoto. |
required |
logger
|
Logger
|
Receives the warnings about ignored keys, capped feature counts and retries. |
required |
**stabilizer_kwargs
|
Any
|
Any |
{}
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
From stabilo, for an invalid parameter combination. In particular |
RuntimeError
|
From a learning-based detector that runs out of memory (also |
Examples:
Register a drone frame to an orthophoto with the shipped matching settings:
import cv2
from geotrax.utils.config_utils import load_config
from geotrax.utils.logging_utils import setup_logger
from geotrax.utils.registration import estimate_homography
logger = setup_logger("register", dry_run=True)
matching = load_config("default", logger)["georef"]["matching"]
frame, ortho = cv2.imread("frame.png"), cv2.imread("ortho.png")
H, inliers, matches, _ = estimate_homography(frame, ortho, logger, **matching)
Source code in geotrax/utils/registration.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
Settings¶
DEFAULT_STABILIZER_KWARGS
module-attribute
¶
DEFAULT_STABILIZER_KWARGS = {'detector_name': 'rsift', 'matcher_name': 'bf', 'filter_type': 'ratio', 'sift_enable_precise_upscale': True, 'rsift_eps': 1e-08, 'max_features': 250000, 'filter_ratio': 0.55, 'ransac_method': cv2.USAC_MAGSAC, 'ransac_epipolar_threshold': 3.0, 'ransac_threshold_space': 'full', 'ransac_max_iter': 10000, 'ransac_confidence': 0.999999, 'clahe': False, 'downsample_ratio': 1.0, 'gpu': False, 'gpu_device_id': 0}
Registration defaults: RootSIFT, brute-force matching with a ratio test, and MAGSAC++.
The single source of truth for registration, and the fallback for any key absent from
georef.matching. Every key can be overridden from the config, the CLI or the keyword arguments
of estimate_homography.
FIXED_STABILIZER_KWARGS
module-attribute
¶
FIXED_STABILIZER_KWARGS = {'transformation_type': 'projective', 'mask_use': False, 'ref_multiplier': 1.0, 'match_query_frame': 'current'}
Registration geometry pinned regardless of the config.
Callers assume a full-resolution 3x3 source-to-destination homography estimated from a single image pair with no exclusion mask, so a supplied value for any of these keys is ignored with a warning.
KNOWN_STABILIZER_KWARGS
module-attribute
¶
KNOWN_STABILIZER_KWARGS = set(DEFAULT_STABILIZER_KWARGS) | set(FIXED_STABILIZER_KWARGS) | {'device', 'loftr_weights', 'loftr_confidence', 'disk_weights', 'dedode_detector_weights', 'dedode_descriptor_weights'}
Every key estimate_homography forwards to the Stabilizer without a warning.
Mirrors georef.matching in default.yaml; extend it together with that block when a new stabilo
option is adopted.
MIN_MAX_FEATURES
module-attribute
¶
Lowest max_features that the halving retry in estimate_homography goes down to.
DL_MAX_FEATURES_CAP
module-attribute
¶
Ceiling on max_features for the learning-based detectors, which consume it as top_k.
Detectors and devices¶
DETECTOR_CHOICES
module-attribute
¶
Every detector name stabilo accepts; the choices of --stab-detector and --geo-detector.
DL_DETECTORS
module-attribute
¶
The learning-based (kornia) detectors, which run on a torch device instead of OpenCV.
DEVICE_CHOICES
module-attribute
¶
Every torch device name stabilo accepts; the choices of --stab-device and --geo-device.