Skip to content

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.

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 is the path the field guide documents end to end, in the Kalibr workflow.

The Kalibr workflow: two recordings, two calibrations A flow chart of the Kalibr workflow for cameras plus an IMU, as the Kalibr wiki describes it. Two recordings, both stored as ROS 1 bags, with the roles swapped. Recording 1, the camera dataset: the cameras stay fixed and the Aprilgrid target is moved in front of them, at around 4 Hz. It goes with target.yaml, which holds the target's measured tag size and spacing, into kalibr_calibrate_cameras, which writes camchain.yaml with each camera's intrinsics and distortion and the camera-to-camera transforms. Recording 2, the camera-IMU dataset: the target stays fixed and the rig is moved to excite every rotation and translation axis; the guide reports good results at a 20 Hz camera rate and 200 Hz IMU rate. It goes with target.yaml, camchain.yaml and imu.yaml, the four IMU noise values from an Allan deviation or the datasheet, into kalibr_calibrate_imu_camera, which writes camchain-imucam.yaml, adding T_cam_imu and timeshift_cam_imu to each camera. Both tools also write a results text file and a PDF report to judge before accepting. Recording 1 cameras fixed, target moved in front camera rate ~4 Hz target.yaml measured tag size, spacing Recording 2 target fixed, rig moved on every axis; e.g. camera 20 Hz, IMU 200 Hz imu.yaml 4 noise values kalibr_calibrate_cameras camera calibration kalibr_calibrate_imu_camera camera–IMU calibration camchain.yaml intrinsics, distortion, camera-to-camera transforms camchain-imucam.yaml camchain plus T_cam_imu and timeshift_cam_imu per camera camchain.yaml feeds in check: results-cam.txt, report-cam.pdf check: results-imucam.txt, report-imucam.pdf Both recordings are ROS 1 bags. The roles swap: cameras still, then target still
Kalibr's two calibrations and the files that pass between them. The camera calibration uses a recording in which the cameras stay still and the target moves; the camera–IMU calibration uses one in which the target stays still and the rig moves on every axis, and it takes camchain.yaml from the first step plus the IMU noise values in imu.yaml. Rates are the Kalibr wiki's suggestions (about 4 Hz for the first recording; 20 Hz camera and 200 Hz IMU for the second). Each tool also writes a results file and a PDF report to judge before you accept the output.

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:

Terminal window
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:

Terminal window
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 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).

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.

What calibration tools report about themselves Three results, each from a tool's own paper, not a head-to-head benchmark. One, BabelCalib's fisheye and catadioptric benchmark: calibration failure rates of 24 percent for Kalibr and for OpenCV with the Kannala-Brandt model, 34 percent for Kalibr with FOV, 51 percent for Kalibr with EUCM, and 0 percent for BabelCalib. Two, AprilCal's user study against a 65-image reference set: guided capture gave 0.229 px mean and 1.651 px maximum test error; unguided OpenCV checkerboard capture gave 0.728 px mean and 38.646 px maximum, on a logarithmic scale. Three, OpenVINS simulation, 20 Monte-Carlo runs started from a deliberately bad calibration: average position error 508.719 m with online calibration off and 0.139 m with it on, on a logarithmic scale. BabelCalib benchmark: calibration failure rate 0% 20% 40% 60% Kalibr, Kannala–Brandt 24% OpenCV, Kannala–Brandt 24% Kalibr, FOV 34% Kalibr, EUCM 51% BabelCalib 0%: no failures AprilCal user study: test reprojection error (log scale) 0.1 1 10 100 px Guided (AprilCal), mean 0.229 px max 1.651 px Unguided (OpenCV), mean 0.728 px max 38.646 px OpenVINS simulation from a bad calibration: position error (log scale) 0.1 1 10 100 1000 m online calibration off 508.719 m online calibration on 0.139 m
Three results reported in the tools' own papers, not a head-to-head benchmark: calibration failure rates on BabelCalib's fisheye and catadioptric benchmark; test reprojection error for guided (AprilCal) and unguided (OpenCV checkerboard) capture in AprilCal's user study; and OpenVINS position error in simulation when starting from a deliberately bad calibration, with online calibration off and on. The lower two panels use logarithmic scales.
  1. Your recording is a ROS 2 bag. What does Kalibr need, and how does the field guide say to get it?
  2. You run kalibr_calibrate_cameras --topics /cam1/image_raw /cam0/image_raw .... Which physical camera is cam0 in the output?
  3. 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?
  4. Why does OpenCV recommend CALIB_FIX_INTRINSIC in stereoCalibrate?
  1. A ROS 1 bag. Convert it with the rosbags package (rosbags-convert), or export the images and build a bag with kalibr_bagcreater.
  2. The camera on /cam1/image_raw. The order of --topics and --models sets the camera numbering.
  3. No. mrcal-from-kalibr supports 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.
  4. 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.