ds_msp.calib¶
Generic calibration (bundle adjustment) for any CameraModel. See
Calibrate any model for task recipes and the
capstone for a full worked example.
ds_msp.calib ¶
Generic calibration (bundle adjustment) for any CameraModel.
calibrate and AprilGridTarget are dependency-light. detect_aprilgrid
needs the optional aprilgrid backend (pip install ds_msp[calib]) and is
imported lazily so this package stays importable without it.
load_camera re-exports :func:ds_msp.io.kalibr.load_kalibr under a name that doesn't
require knowing the output is Kalibr-formatted — ds-msp-calibrate's output is meant to be
loaded straight back into a ready :class:~ds_msp.core.contracts.CameraModel instance, not
inspected as a file format.
AprilGridTarget ¶
A Kalibr-style AprilGrid: a rows x cols grid of AprilTags.
Geometry follows Kalibr's convention exactly so detections from a board calibrated by Kalibr/Basalt line up:
- Tag ids run row-major from the bottom-left corner:
id = row * cols + col. - Each tag's four corners are ordered counter-clockwise starting bottom-left
(BL, BR, TR, TL)— the same order the AprilGrid detector returns them. - Tags are squares of side
tag_size(metres) separated by a gap oftag_spacing * tag_size(tag_spacingis Kalibr's gap/size ratio).
tag_size only sets absolute scale, which affects the recovered extrinsic
translations, not the intrinsics — so a slightly wrong board size still yields
correct fx, fy, cx, cy and distortion.
Source code in ds_msp/calib/targets.py
all_object_points ¶
build_correspondences ¶
build_correspondences(detections_per_image: List[Mapping[int, ndarray]], *, min_corners: int = 8) -> Tuple[List[np.ndarray], List[np.ndarray], List[np.ndarray]]
Turn per-image {tag_id: (4, 2) pixels} into calibration inputs.
Returns (X_world_list, keypoints_list, visibility_list) ready for
ds_msp.calib.bundle.calibrate. Images with fewer than min_corners
detected corners are dropped (too few to constrain a pose).
Source code in ds_msp/calib/targets.py
object_points ¶
3D board coordinates (metres) of one tag's 4 corners, (4, 3).
Order matches the detector: bottom-left, bottom-right, top-right, top-left.
Source code in ds_msp/calib/targets.py
calibrate ¶
calibrate(init_model: CameraModel, X_world_list: List[ndarray], keypoints_list: List[ndarray], visibility_list: List[ndarray], *, max_nfev: int = 200, verbose: int = 0, robust: str = 'cauchy', robust_scale: 'float | str' = 'auto', gnc: bool = False, multi_start: bool = True, n_restarts: int = 4, seed: int = 0, force_multistart: bool = True, loss: str | None = None, f_scale: float | None = None) -> Dict
Calibrate any model from checkerboard correspondences — robust by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robust
|
str
|
Redescending IRLS kernel applied in the BA loop: |
'cauchy'
|
robust_scale
|
float | str
|
Inlier scale (px) where down-weighting begins, or |
'auto'
|
gnc
|
bool
|
Run a graduated-non-convexity anneal (default |
False
|
multi_start
|
bool
|
Model-aware multi-start auto-init (default |
True
|
n_restarts
|
int
|
Number of dispersed shape seeds for |
4
|
force_multistart
|
bool
|
Kept for API stability (default |
True
|
loss
|
str
|
SciPy-style loss name ( |
None
|
f_scale
|
float
|
Fixed inlier scale (px) for the legacy |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
The refined |
Source code in ds_msp/calib/bundle.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
estimate_relative_pose ¶
Estimate the rigid transform T_to_from between two cameras.
Given board poses observed by each camera on the same frames
(poses_from[i] and poses_to[i] are the board seen at frame i by the
"from" and "to" cameras), returns the transform that maps a point in the from
camera's frame into the to camera's frame — e.g. pass cam0 then cam1 to get
Kalibr's T_cn_cnm1 (= T_cam1_cam0).
Each frame yields one estimate T_to_board ∘ (T_from_board)^-1; the rotations
are averaged on SO(3) (chordal / SVD projection) and the translation by the
component-wise median (robust to per-frame PnP noise).
Returns {T, R, t, n, rot_rms_deg, t_std_mm} where T is 4x4 and
rot_rms_deg / t_std_mm report how consistent the per-frame estimates are.
Source code in ds_msp/calib/stereo.py
relative_pose_error ¶
Compare two rigid transforms: rotation angle (deg) and translation error (mm).