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.
Part A: Kalibr
Section titled “Part A: Kalibr”Step 1: Set up Kalibr
Section titled “Step 1: Set up Kalibr”Kalibr needs ROS 1. The Kalibr wiki’s installation page gives a Docker image for systems without it. Build it:
git clone https://github.com/ethz-asl/kalibr.gitcd kalibrdocker build -t kalibr -f Dockerfile_ros1_20_04 . # change this to whatever ubuntu version you wantThen start the container with your data folder mounted at /data:
FOLDER=/path/to/your/data/on/hostxhost +local:rootdocker run -it -e "DISPLAY" -e "QT_X11_NO_MITSHM=1" \ -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" \ -v "$FOLDER:/data" kalibrInside 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.
Step 2: Lock the cameras
Section titled “Step 2: Lock the cameras”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:
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.
Step 3: Make and measure the target
Section titled “Step 3: Make and measure the target”Generate an Aprilgrid with the wiki’s target script:
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:
- Print it and glue it flat to a rigid plate.
- Keep a white border at least one grid element wide.
- Measure it. Measure
tagSizeacross 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). - Write
target.yamlwith the measured numbers, in the wiki’s format:
target_type: 'aprilgrid' #gridtypetagCols: [NUM_COLS] #number of apriltagstagRows: [NUM_ROWS] #number of apriltagstagSize: [MEASURED_M] #size of apriltag, edge to edge [m]tagSpacing: [GAP/TAGSIZE] #ratio of space between tags to tagSizeYou 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).
Step 4: Record the camera sequence
Section titled “Step 4: Record the camera sequence”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).
Step 5: Get the data into a ROS 1 bag
Section titled “Step 5: Get the data into a ROS 1 bag”Kalibr reads only ROS 1 bags. Use whichever fits your recorder (Kalibr workflow, step 4):
- A ROS 2 bag: convert it with the
rosbagspackage, 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:
pip3 install "rosbags>=0.9.12" # might need -Urosbags-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/andcam1/, each file named by its timestamp in nanoseconds, such as1385030208726607500.png, and build a bag with the bagcreater:
kalibr_bagcreater --folder dataset-dir/. --output-bag awsome.bagThe 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):
rosbag info [calib.bag]You should see one image topic per camera, with similar message counts.
Step 6: Calibrate the cameras
Section titled “Step 6: Calibrate the cameras”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:
rosrun kalibr kalibr_calibrate_cameras \ --bag /data/[calib.bag] --target /data/target.yaml \ --models [MODEL_0] [MODEL_1] \ --topics /cam0/image_raw /cam1/image_rawThe 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.
Step 7: Read the result
Section titled “Step 7: Read the result”Open <bag>-results-cam.txt and <bag>-report-cam.pdf and work through Lesson 4:
- The target block at the end of the results file holds the dimensions you measured.
- The reprojection error for each camera: a mean close to zero in x and y, and a spread similar for both cameras.
- The parameter standard deviations (the “+-” values): none large relative to its value.
- The corner plot on each camera’s reprojection-errors page: detections reach all four edges and corners.
- The polar error page: error stays flat out to the widest angle.
- The Obs. graph page: the two cameras are linked by shared observations.
- The baseline: the translation in
T_cn_cnm1for 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.
Step 8: Calibrate again and compare
Section titled “Step 8: Calibrate again and compare”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):
kalibr_camera_validator --cam camchain.yaml --target target.yamlStep 9: Check against known geometry
Section titled “Step 9: Check against known geometry”- 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).
Step 10: Sign off and store
Section titled “Step 10: Sign off and store”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.
B1: Install
Section titled “B1: Install”On Debian 12 or Ubuntu 22.04 and later, the install page gives:
apt install mrcal libmrcal-dev python3-mrcalThe chessboard corner finder, mrgingham, is a separate package: apt install mrgingham.
B2: Target and recording
Section titled “B2: Target and recording”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.
B3: Calibrate
Section titled “B3: Calibrate”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:
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.
B4: Uncertainty and cross-validation
Section titled “B4: Uncertainty and cross-validation”For each camera, map the projection uncertainty:
mrcal-show-projection-uncertainty camera-0.cameramodelWhere 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:
mrcal-show-projection-diff [dance1]/camera-0.cameramodel [dance2]/camera-0.cameramodelYou 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:
mrcal-show-residuals-board-observation \ --from-worst \ --vectorscale 100 \ camera-0.cameramodel \ 0-5The guide uses this to spot detector errors, rolling shutter, synchronisation errors and an unmodelled board shape by their residual patterns.
Sources
Section titled “Sources”- Kalibr wiki, ETH Zurich ASL: installation, calibration targets, multiple-camera calibration, bag format, ROS 2 calibration, camera focus, calibration validator.
- Kalibr source code, github.com/ethz-asl/kalibr (commit
1f60227):kalibr_calibrate_camerasandkalibr_create_target_pdfoptions. - ROS wiki: rosbag command line.
- Kogan, D. mrcal: how to calibrate, install, cross-validation, and the mrcal-from-kalibr source.
- Field guide: Kalibr Workflow, Kalibr File Reference, Calibration Targets and Calibration Sequences, Judging a Calibration, Camera Calibration.