C201 Lesson 3: Running the Solver with Kalibr, mrcal or OpenCV
With a measured target and a recording, a solver turns corner detections into intrinsics and extrinsics. This lesson compares the three tools the field guide covers for a stereo pair, Kalibr, mrcal and OpenCV, and shows the commands as each tool’s documentation gives them. The lab runs them on your own rig. The tool-by-tool comparison is on Calibration Tools Compared.
The three tools at a glance
Section titled “The three tools at a glance”| Kalibr | mrcal | OpenCV | |
|---|---|---|---|
| Input | a ROS 1 bag | images, plus a table of corner detections | arrays of 2D–3D point pairs |
| Target | Aprilgrid (recommended), checkerboard, circle grid | chessboard with the mrgingham detector recommended; other detectors through a corners file | chessboard, circle grid and ChArUco detectors |
| Cameras | any number; neighbouring cameras must overlap | any number, one lens model for all of them | one camera, or one pair with stereoCalibrate |
| Fisheye models | pinhole-equi, omni-radtan, eucm-none, ds-none |
LENSMODEL_SPLINED_STEREOGRAPHIC and others |
cv::fisheye (Kannala–Brandt), cv::omnidir (contrib) |
| Quality output | reprojection errors, parameter standard deviations, a PDF report | projection uncertainty, cross-validation diffs, residual plots | reprojection error |
| Licence | BSD-style with an advertising clause | Apache-2.0 | Apache-2.0 |
Sources: Calibration Tools Compared, Calibrating a Stereo or Multi-Camera Rig and mrcal’s how-to-calibrate guide.
Kalibr
Section titled “Kalibr”Kalibr is the path the field guide documents end to end, in the Kalibr workflow.
Getting the data in. Kalibr reads only ROS 1 bags. The bag format page gives two ways in besides recording a ROS 1 bag directly: convert a ROS 2 bag with the rosbags package, or build a bag from image files with kalibr_bagcreater, each camera’s images in their own folder and named by their timestamps in nanoseconds (Kalibr workflow, step 4).
Choosing a model per camera. --models takes one projection–distortion pair per camera, and Kalibr can fit a different model to each camera in one run. For fisheye lenses the field guide’s model table points to pinhole-equi (Kannala–Brandt), ds-none or eucm-none, and away from pinhole-equi near 180°.
Running it. The multiple-camera guide gives the command in this form:
kalibr_calibrate_cameras --bag [filename.bag] --topics [TOPIC_0 ... TOPIC_N] --models [MODEL_0 ... MODEL_N] --target [target.yaml]The order of --topics and --models sets which camera is cam0 and which is cam1. Two of the options the field guide explains: --show-extraction to watch the target detection, and --bag-freq to extract features at a set rate (Kalibr File Reference). If the optimisation diverges in the first few images, the wiki’s advice is to “just try to restart the calibration as the initial guesses are based on a random pick of images.”
What comes out. <bag>-camchain.yaml (the intrinsics, distortion and T_cn_cnm1 for each camera), <bag>-results-cam.txt and <bag>-report-cam.pdf (Kalibr workflow, step 5).
mrcal, “originally built at NASA/JPL to generate the high-accuracy calibrations demanded by long-range stereo” (mrcal), is the tool the field guide uses for judging a calibration: it reports projection uncertainty and supports cross-validation (lesson 4).
Model choice. The how-to-calibrate guide recommends its splined model, LENSMODEL_SPLINED_STEREOGRAPHIC, for every lens: it “works very well, and is able to represent real-world lenses better than the parametric models”. The model takes a horizontal field of view, fov_x_deg, which the guide says to start from the lens datasheet and then check with mrcal-show-splined-model-correction. A splined model needs dense target coverage, because a spline is only constrained where there is data (Lens Projections and Distortion). mrcal fits one lens model to all cameras in a run; the guide calls that “a current limitation of mrcal”.
Running it. The guide’s example invocation, for one camera:
mrcal-calibrate-cameras \ --corners-cache corners.vnl \ --lensmodel LENSMODEL_SPLINED_STEREOGRAPHIC_order=3_Nx=30_Ny=18_fov_x_deg=150 \ --focal 1900 \ --object-spacing 0.0588 \ --object-width-n 14 \ '*.JPG'Those numbers belong to the guide’s own lens and board. --object-spacing is the measured distance between neighbouring corners, --object-width-n the corner count across the board, and --focal a rough starting focal length in pixels. For a stereo pair, give one quoted glob per camera, such as 'frame*-camera0.png' 'frame*-camera1.png': images with the same frame number are taken as captured at the same instant. If the corners file does not exist yet, the tool runs mrgingham and writes it. The output is one camera-N.cameramodel file per camera.
Moving between tools. mrcal ships mrcal-from-kalibr and mrcal-to-kalibr (Calibration Tools Compared). Check the converter’s own notes before relying on it for a fisheye pair: its documentation says it currently supports only Kalibr’s pinhole camera with radtan or no distortion. Its uncertainty tool also needs the solve’s optimisation inputs; for a model without them, mrcal-show-projection-uncertainty stops with “optimization_inputs are unavailable in this model”. So a Kalibr fisheye calibration cannot be judged with mrcal’s uncertainty map by conversion; calibrate in mrcal itself for that.
OpenCV
Section titled “OpenCV”OpenCV calibrates one camera at a time, or one pair. Its fisheye module implements the Kannala–Brandt model, and cv::omnidir in opencv_contrib implements Mei’s unified model (Calibration Tools Compared).
The order matters. OpenCV’s own documentation warns that estimating everything at once “can diverge from the correct solution”, and advises: “If the intrinsic parameters can be estimated with high accuracy for each of the cameras individually (for example, using calibrateCamera ), you are recommended to do so and then pass CALIB_FIX_INTRINSIC flag to the function along with the computed intrinsic parameters” (OpenCV calib3d reference). Its stereoRectify is pinhole rectification only, which cannot hold a full fisheye view (Rectify, or work in rays).
The same order in every tool
Section titled “The same order in every tool”Intrinsics first, then the pair. OpenCV advises it directly; TUM VI followed the same order across sensors; Kalibr solves the cameras and their chain before any IMU step. When a fisheye solve fails outright, the field guide’s stereo page reports BabelCalib’s finding that Kalibr and OpenCV both failed 24% of the time with Kannala–Brandt on its fisheye and catadioptric benchmark, and that BabelCalib, which needs no initial guess, had no failures; it calibrates one camera per call.
Self-check
Section titled “Self-check”- Your recording is a ROS 2 bag. What does Kalibr need, and how does the field guide say to get it?
- You run
kalibr_calibrate_cameras --topics /cam1/image_raw /cam0/image_raw .... Which physical camera is cam0 in the output? - You want mrcal’s projection-uncertainty map for a calibration you solved in Kalibr with
ds-none. Can you convert it and plot the map? - Why does OpenCV recommend
CALIB_FIX_INTRINSICinstereoCalibrate?
Answers
Section titled “Answers”- A ROS 1 bag. Convert it with the
rosbagspackage (rosbags-convert), or export the images and build a bag withkalibr_bagcreater. - The camera on
/cam1/image_raw. The order of--topicsand--modelssets the camera numbering. - No.
mrcal-from-kalibrsupports only Kalibr’s pinhole camera with radtan or no distortion, and the uncertainty tool needs the optimisation inputs that only an mrcal solve stores. Calibrate in mrcal to get the map. - Estimating every parameter at once can diverge from the correct solution. Calibrating each camera first and fixing those intrinsics leaves the stereo step only the transform between them.
Sources
Section titled “Sources”- Field guide: Kalibr Workflow, Kalibr File Reference, Calibration Tools Compared, Calibrating a Stereo or Multi-Camera Rig, Lens Projections and Distortion.
- Kalibr wiki, ETH Zurich ASL: multiple-camera calibration and bag format.
- Kogan, D. mrcal, its how-to-calibrate guide, and the mrcal-from-kalibr and mrcal-show-projection-uncertainty tool sources.
- OpenCV calib3d module reference (
stereoCalibrate,stereoRectify).