Stereo Calibration using the Matlab Toolbox and Octave

The Camera Calibration Toolbox is a matlab plug-in which can be used to calibrate cameras. Since it is using some GUI features that octave does not provide, it does not run out of the box in octave. Nevertheless, the basic functionality can also be achieved without it. The basic idea comes from here.

Getting it to work with Ubuntu 10.04, I had to do the following:

sudo apt-get install octave gnuplot octave-plot octave-image imagemagick

Firing up octave and performing

addpath <path to installed toolbox>

puts the toolbox into the path.

Now it is possible to run the individual steps for calibration using the following commands:

  • Image names -- data_calib
  • Read images -- ima_read_calib
  • Extract grid corners -- click_calib
  • Calibration -- go_calib_optim
  • Show Extrinsic -- ext_calib
  • Reproject on images -- reproject_calib
  • Analyse error -- analyse_error
  • Recomp. corners -- recomp_corner_calib
  • Add/Suppress images -- add_suppress
  • Save -- saving_calib
  • Load -- loading_calib

The sequence of things you need to do is described in the first tutorial from the toolbox.

There was one problem with the selection of image corners. The bug seems to be described here.

What I had to to was add

fputs (ostream, "unset multiplot;\n\n");
fputs (ostream, "set mouse;\n\npause mouse;\n\n");

in /usr/share/octave/3.2.4/m/plot/__gnuplot_ginput__.m (I added it after unwind_protect).

For the stereo calibration you have to perform calibration of the left and right camera separately and rename Calib_Results (seems to be save without .mat in octave) to Calib_Results_left.mat or right respectively.

Afterwarts you can use the calibration functions as listed here:

  • Load left and right calibration files -- load_stereo_calib_files
  • Run stereo calibration -- go_calib_stereo
  • Show Extrinsics of stereo rig -- ext_calib_stereo
  • Show Intrinsic parameters -- show_stereo_calib_results
  • Save stereo calib results -- saving_stereo_calib
  • Load stereo calib results -- loading_stereo_calib
  • Rectify the calibration images -- rectify_stereo_pair

Walkthrough for a calibration when everything is installed

  • Record a log which contains to synchronised streams camera_left and camera_right
  • Extract stereo images using the the script in image_processing/orogen/stereo/scripts

./log2calib.rb path_to/camera.0.log calibration_dir

  • pick around 15 images with the gui, which will be saved as left_xx.png right_xx.png in the output directory
  • batch convert the .png to .tif files using imagemagick

mogrify -format tif *.png

  • open octave and run addpath to the calibration toolbox (see above)
  • run data_calib using left_ as prefix and tif als file format
  • run click_calib and select the image corner for each of the images
  • run go_calib_optim afterwards have a look at the errors using analyse_error
  • look at the tutorial on how to remove outliers if there are any
  • save the calibration values running saving_calib
  • in a shell mv Calib_Results Calib_Results_left.mat
  • Start again with data_calib, but now for the right image
  • run load_stereo_calib_files
  • run go_calib_stereo
  • copy paste the resulting parameters into a text file

Using the resulting text file in Rock

In order to use the resulting calibration, there are two ways of getting it into rock. One is in the StereoCalibration class, which has a fromMatlabFile function.

The other method is using a ruby class currently in the stereo orogen module. This one needs to be integrated a little better though.

In the stereo orogen module, there also is a script log_2_calib.rb which helps getting the calibration images from rock camera log files in the first place.

Last modified 3 years ago Last modified on 11/16/15 09:16:37