Cal3f is our simplest tunable calibration model, consisting of a single focal length. It assumes square pixels and zero skew, with fx = fy = f; the principal point is fixed.
import gtsam
import numpy as npInitialization¶
The explicit constructor makes the model and parameter order visible. A default constructor is also available, but calibrated values are preferable in real projection code.
calibration = gtsam.Cal3f(800.0, 320.0, 240.0)
print(calibration)Calibration parameters¶
f() is the shared focal length; px() and py() are retained as fixed projection constants. vector() collects the optimized parameters, while K() returns the intrinsic matrix associated with the linear part of the model.
print("focal length:", calibration.f())
print("principal point:", calibration.principalPoint())
print("optimized vector:", calibration.vector())
print("manifold dimension:", calibration.dim())Calibrating and uncalibrating points¶
uncalibrate() maps normalized image coordinates to pixels and applies this model’s distortion. calibrate() performs the inverse mapping iteratively. Their round trip is the most direct way to check parameter conventions.
normalized = np.array([0.12, -0.08])
pixel = calibration.uncalibrate(normalized)
recovered = calibration.calibrate(pixel)
print("pixel:", pixel)
print("recovered normalized point:", recovered)
np.testing.assert_allclose(recovered, normalized, atol=1e-7)Manifold operations¶
Calibration objects participate in nonlinear optimization through retract() and localCoordinates(). The tangent coordinates follow the order returned by vector() for the parameters that this model optimizes.
delta = np.array([2.0])
perturbed = calibration.retract(delta)
recovered_delta = calibration.localCoordinates(perturbed)
print("parameter increment:", recovered_delta)
np.testing.assert_allclose(recovered_delta, delta, atol=1e-9)