Skip to content

C201 Lab: Calibrate Your Fisheye Stereo Rig

This lab calibrates the cameras of your rig: each camera’s intrinsics and the transform between the two cameras of a stereo pair. Camera-to-IMU calibration is course C202; steps 6 to 9 of the Kalibr workflow cover it.

The main path is Kalibr, which the field guide documents end to end. Part B is an optional mrcal path for teams that want projection uncertainty and cross-validation. Every command below is copied from the tool’s own documentation, or follows its documented form with your own file names; the source is linked at each step. Square brackets mark values you fill in.

Work through Lessons 1 to 4 first, and keep the checklist next to you.

Kalibr needs ROS 1. The Kalibr wiki’s installation page gives a Docker image for systems without it. Build it:

Terminal window
git clone https://github.com/ethz-asl/kalibr.git
cd kalibr
docker build -t kalibr -f Dockerfile_ros1_20_04 . # change this to whatever ubuntu version you want

Then start the container with your data folder mounted at /data:

Terminal window
FOLDER=/path/to/your/data/on/host
xhost +local:root
docker run -it -e "DISPLAY" -e "QT_X11_NO_MITSHM=1" \
-v "/tmp/.X11-unix:/tmp/.X11-unix:rw" \
-v "$FOLDER:/data" kalibr

Inside the container, load the ROS environment with source devel/setup.bash. The installation page’s example then runs each tool as rosrun kalibr <tool>; the other wiki pages show the bare tool name. The commands below keep the form of the page they come from.

You should see a shell prompt inside the container, and your data folder’s files under /data.

If it fails: every tool also lists its options with --h (Kalibr File Reference). If plots or the report window do not open, the DISPLAY and X11 lines above are what pass the display into the container.

Fix everything the intrinsics depend on, in its final working state (Lesson 1, Kalibr workflow, step 1):

  • resolution, crop and binning mode;
  • focus, with autofocus off; lock a manual focus ring mechanically if you can;
  • optical and electronic stabilisation off;
  • a short, fixed exposure in good light, so the corners stay sharp without extra gain noise (why bright, even light).

If the lenses have a manual focus ring and the cameras publish a live ROS image topic, Kalibr’s camera focus tool helps set it the same way every time:

Terminal window
kalibr_camera_focus --topic [IMAGE_TOPIC]

You should see the live image with a focus measure. The wiki’s instruction: point the camera at a detailed scene, such as a Siemens star or a checkerboard, “and adjust the focus while trying to minimize the calculated focus measure.”

Write down the resolution, focus, exposure and each camera’s serial number. They are part of the calibration.

Generate an Aprilgrid with the wiki’s target script:

Terminal window
rosrun kalibr kalibr_create_target_pdf --type apriltag --nx [NUM_COLS] --ny [NUM_ROWS] --tsize [TAG_WIDTH_M] --tspace [TAG_SPACING_PERCENT]

Despite PERCENT in the wiki’s placeholder, --tspace is a fraction such as 0.3, not 30; --tsize is in metres (kalibr_create_target_pdf). Size the board for your lenses: at the same range a bigger board is better, and mrcal’s choreography study found that “we care about the size of the chessboard relative to its distance from the camera” (targets page).

Then:

  1. Print it and glue it flat to a rigid plate.
  2. Keep a white border at least one grid element wide.
  3. Measure it. Measure tagSize across one tag’s outer black edges, and the gap between two neighbouring tags. Measuring across many tags and dividing reduces the error (Measuring a printed target).
  4. Write target.yaml with the measured numbers, in the wiki’s format:
target_type: 'aprilgrid' #gridtype
tagCols: [NUM_COLS] #number of apriltags
tagRows: [NUM_ROWS] #number of apriltags
tagSize: [MEASURED_M] #size of apriltag, edge to edge [m]
tagSpacing: [GAP/TAGSIZE] #ratio of space between tags to tagSize

You should see a tagSpacing between 0 and 1, and a tagSize with a decimal point.

If it fails: write lengths with a decimal point, such as 0.06; a bare 1 is read as an integer and fails Kalibr’s check. tagSpacing is a ratio: writing the gap in metres puts every corner in the wrong place (target.yaml).

What tagSize and tagSpacing measure on a Kalibr Aprilgrid Two neighbouring AprilTags from a Kalibr Aprilgrid, with small black corner squares in the gaps between them. tagSize is the width of one tag, measured edge to edge across its black border, in metres. The gap between two tags is the spacing in metres. tagSpacing in the YAML file is not that gap: it is the gap divided by tagSize, a ratio with no unit. The example from the Kalibr wiki: a 2 m tag with a 0.5 m gap gives tagSpacing 0.25. tagSize, edge to edge [m] gap [m] tagSpacing = gap / tagSize example: 0.5 m / 2 m = 0.25 (no unit)
On an Aprilgrid, tagSize is the width of one tag across its black border, in metres. tagSpacing is not a length: it is the gap between tags divided by tagSize. The small black squares fill the gaps at the tag corners.

The rig stays still and the target moves. Kalibr’s multiple-camera guide recommends lowering the camera rate “to around 4 Hz while capturing the calibration data”, which it says “reduces redundant information in the dataset”. Hide every other AprilTag in the room: a stray tag can carry the same ID as one of the grid’s (Lesson 2).

Plan the motion before you start (Lesson 2):

  • Close-ups for each camera on its own, filling as much of its image as you can, tilted forward, back, left and right.
  • The image corners and edges of both cameras. Let the board run off the edge: an Aprilgrid still gives corners from a partial view.
  • Shared views, with the board seen by both cameras at once, from just far enough out.
  • Slow, smooth motion, so the corners stay sharp.

You should see, on a live view, the board reaching every part of both images over the recording.

If it fails: if you cannot see a live view, record more than you think you need and check coverage in the report (step 7). In the AprilCal study, novices following written instructions missed the image corners (targets page).

Kalibr reads only ROS 1 bags. Use whichever fits your recorder (Kalibr workflow, step 4):

  • A ROS 2 bag: convert it with the rosbags package, as the wiki’s ROS 2 guide shows. The wiki writes the version requirement without quotes; a shell reads the unquoted > as a redirect, so it is quoted here:
Terminal window
pip3 install "rosbags>=0.9.12" # might need -U
rosbags-convert <ros2_bag_folder> --dst calib_01.bag --exclude-topic <non_img_and_imu_topics>
  • Image files: put each camera’s images in its own folder, cam0/ and cam1/, each file named by its timestamp in nanoseconds, such as 1385030208726607500.png, and build a bag with the bagcreater:
Terminal window
kalibr_bagcreater --folder dataset-dir/. --output-bag awsome.bag

The topics come out as /cam0/image_raw and /cam1/image_raw. Kalibr uses the timestamps you put in; it does not correct them.

Checkpoint: inside the container, rosbag info gives a summary of a bag, including its topics, message counts and frequency (ROS rosbag command line):

Terminal window
rosbag info [calib.bag]

You should see one image topic per camera, with similar message counts.

Choose a model for each camera (Lesson 3): pinhole-equi (Kannala–Brandt) for a fisheye short of 180°, or ds-none or eucm-none, which also suit lenses near or beyond 180°. Use the model your pipeline consumes. Then run, in the form the installation page uses inside the container:

Terminal window
rosrun kalibr kalibr_calibrate_cameras \
--bag /data/[calib.bag] --target /data/target.yaml \
--models [MODEL_0] [MODEL_1] \
--topics /cam0/image_raw /cam1/image_raw

The order of --topics and --models sets which camera is cam0.

You should see three files when it finishes: <bag>-camchain.yaml, <bag>-results-cam.txt and <bag>-report-cam.pdf (Kalibr File Reference).

If it fails:

Symptom What the sources say to do
“Cameras are not connected through mutual observations” record more frames with the target in both cameras; check that the cameras are synchronised; the message suggests “Maybe adjust the approx. sync. tolerance” (--approx-sync, default 0.02 s)
Optimisation diverges in the first images “just try to restart the calibration as the initial guesses are based on a random pick of images”
Target never or rarely detected add --show-extraction to watch detection; check target.yaml, the white border, other AprilTags in view and blur
Few frames used a frame only counts with more tags than the grid’s longer side: at least 7 on a 6 × 6 grid
“Omni with equidistant model not yet supported!” use omni-radtan or another model

Sources: Kalibr workflow, common failures and Kalibr File Reference.

Open <bag>-results-cam.txt and <bag>-report-cam.pdf and work through Lesson 4:

  1. The target block at the end of the results file holds the dimensions you measured.
  2. The reprojection error for each camera: a mean close to zero in x and y, and a spread similar for both cameras.
  3. The parameter standard deviations (the “+-” values): none large relative to its value.
  4. The corner plot on each camera’s reprojection-errors page: detections reach all four edges and corners.
  5. The polar error page: error stays flat out to the widest angle.
  6. The Obs. graph page: the two cameras are linked by shared observations.
  7. The baseline: the translation in T_cn_cnm1 for cam1 matches your caliper measurement of the lens spacing.

Pages and lines are described on the Kalibr File Reference.

If a check fails: error rising toward the edge, or no corners there, means record again with edge coverage or try a different fisheye model. A baseline off by the same percentage as every other translation means re-measure the target. Change one thing at a time and solve again.

Record a second, independent sequence under the same settings and calibrate it the same way. From our conversations with people in the industry, values that move a lot between two good recordings were not well determined by either (Kalibr workflow, step 9). Compare the two calibrations in pixels, not parameter by parameter: high-order distortion coefficients can swing widely while the projections stay nearly identical (Judging a Calibration, check 4). The prompts page has a prompt that writes the comparison script.

If your cameras publish live ROS topics, kalibr_camera_validator shows reprojection errors on live images, for each camera and between cameras (calibration validator):

Terminal window
kalibr_camera_validator --cam camchain.yaml --target target.yaml
  • Straight lines: undistort a frame of a scene with straight edges near the image border; they must come out straight (Judging a Calibration, check 5).
  • Depth on a known board: if you run stereo depth, compare it with the board’s pose solved from one camera. A wrong calibration gives depth maps that look sharp but are distorted in scale and shape (check 6).

Go through the sign-off section of the checklist. Then store the calibration with the data: versioned and tied to the unit’s serial number, so a pipeline never processes footage with the wrong unit’s numbers (Camera Calibration). Keep target.yaml, the results file and the report with it.

Part B (optional): judge the intrinsics with mrcal

Section titled “Part B (optional): judge the intrinsics with mrcal”

mrcal reports projection uncertainty and supports cross-validation, the checks Lesson 4 calls the strongest. A Kalibr fisheye result cannot be brought into mrcal for this: mrcal-from-kalibr supports only Kalibr’s pinhole camera with radtan or no distortion (its documentation). So Part B is a separate calibration in mrcal, with its own target and recording. Everything here is from mrcal’s how-to-calibrate guide and install page.

On Debian 12 or Ubuntu 22.04 and later, the install page gives:

Terminal window
apt install mrcal libmrcal-dev python3-mrcal

The chessboard corner finder, mrgingham, is a separate package: apt install mrgingham.

mrcal recommends a chessboard with the mrgingham detector; the mrgingham documentation provides a 14 × 14 chessboard PDF. Print it, mount it flat, and measure the corner spacing. mrgingham reports only complete boards, so watch a live view while you reach for the image edges.

The images must be synchronised across the cameras. Name them frameFFF-cameraCCC.png: images with the same FFF are taken as captured at the same instant, and CCC identifies the camera. Record two independent dances into two folders, for the cross-validation in B4.

Estimate a starting focal length with the guide’s formula, f ≈ imager width in pixels ÷ (4 · tan(horizontal field of view ÷ 4)). Then, in each dance’s folder, run the guide’s command with your values and one glob per camera:

Terminal window
mrcal-calibrate-cameras \
--corners-cache corners.vnl \
--lensmodel LENSMODEL_SPLINED_STEREOGRAPHIC_order=3_Nx=30_Ny=18_fov_x_deg=[FOV] \
--focal [FOCAL_PX] \
--object-spacing [MEASURED_SPACING_M] \
--object-width-n 14 \
'frame*-camera0.png' 'frame*-camera1.png'

You should see camera-0.cameramodel and camera-1.cameramodel written. If corners.vnl does not exist, the tool runs mrgingham first and writes it.

If it fails: the guide notes that without usable joint views the extrinsics are undefined, and the solver complains about a “not positive definite” Hessian. Record more views both cameras share.

For each camera, map the projection uncertainty:

Terminal window
mrcal-show-projection-uncertainty camera-0.cameramodel

Where it is poor, the guide’s advice is that “you need more chessboard observations in that area.” Then compare the two dances’ models of the same camera:

Terminal window
mrcal-show-projection-diff [dance1]/camera-0.cameramodel [dance2]/camera-0.cameramodel

You should see a difference of about the sum of the two uncertainties. Far more than that points to a model error (mrcal cross-validation). To find the cause, look at the worst-fitting observations, as the guide shows:

Terminal window
mrcal-show-residuals-board-observation \
--from-worst \
--vectorscale 100 \
camera-0.cameramodel \
0-5

The guide uses this to spot detector errors, rolling shutter, synchronisation errors and an unmodelled board shape by their residual patterns.