Fully automatic camera and hand to eye calibration

In case you want to scale the grid, lets say to dX=4mm and dY=4mm, simply type
>>dX=4 >>dY=4

before launching
>>autocalibrate

In case all your images are rejected, you might change
MAX_ERROR to a higher value (in the file autocalibrate.m)

If your grid is bigger than the one that is actually fit, you might consider changing the values

In a first version there were some files missing for the calibration, I added them now to the archive, please re-download if the examples are not working and matlab tells you that some functions are missing. Sorry for the inconvenience!
Just have ssen that some more files were missing, I retested everything and the package should be complete, sorry again!

This are actually two add-ons for the calibration toolbox from Jean-Yves Bouguet [1]. The first part covers a fully automatic calibration procedure and the second covers the calibration of the camera to a robot-arm or an external marker (known as Hand-Eye claibration)

It was basically intended to be used for endoscope calibration [8,9], but can of course be used for other settings as well. Instead of using a chessboard grid, we propose a dotted grid, having two special marks identifying the grid's local coordinate system center. The standard chessboard can still be used for calibration also for the hand-eye calibration (see the image below).

My system consists of a 10mm endoscope attached to a CCD firewire camera, which is tracked using the EasyTrack500 IR active tracking system from atracsys llc

Grid design

The reason for this newly designed are:

Below is an image of the grid through an endoscope:

In order to work, the two special marks should be visible in each camera image. Otherwise the autocalibrate routine will simply ignore the images without them.
The detector can cope with extremely inhomgenous illumination and even specular reflections (as long as the two main marks are visible).

The grid can be downloaded here:

Installation

You need to have Matlab (I only tested on version >6.5) and the calibration toolbox [1] installed on your system and the path set up correctly.
The grid extraction process using the proposed grid uses some functions from the Image Processing Toolbox (MathWorks), if you don't have this toolbox, drop me a line, I'm considering rewriting some parts for use without this toolbox.

The Hand-Eye calibration does not need any additional toolboxes.

Download the archive and extract wherever you want. Then set up the path to this directory. That should already do it.

Usage

In generall the code should be quite well documented fo further help.

Grid detector

Start your Matlab and then start the calibration toolbox GUI and load your images.

Depending on what you want to do, you might set up some variables:

doShowSet doShow = 1 if you want to see what the calibration is doing
doRefineGridSet doRefineGrid = 1 if the grid should be refined after detection, does not really change much
isStronglyDistortedSet isStronglyDistorted = 1, if your images show severe distortion, such as from an endoscope or extremely wide optics (if you just have some distortion, still set this to 0, I'm talking about extreme cases, it is also much slower than the normal method
doIterateCalibrationSet doIterateCalibration = 1, if you want the system to give the best results. This will try to detect wrong correspondences and calibrate again [default], set to 0 if you dont want to use this feature.

If you dont need these settings, you don't need to set up anything.

In order to run the calibration, type

>>autocalibrate

However, you might consider clicking on "Analyze error" in the calib_gui, in order to check whether te backprojection error is ok in each image and remove/suppress images with a high error. Then hit "Calibration": once again.

This should run immediately through all your images and deliver the calibration results at the end.

Note: This calibration uses two functions from Peter Kovesi ("MATLAB and Octave Functions for Computer Vision and Image Processing", http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/index.html), but for convenience, I included these two files in my package.

Hand-Eye calibration

After calibration, either having used the above method or the standard chessboard, you can start the hand to eye calibration, if your camera is either mounted on a robot arm or is tracked with an external tracking device. In this case you must give the system the pose/transformation from the robot/tracker coordinate system to the robot hand/marker in homogenous representation. The data of allviews are packed together in a 4x4xNumber_of_Views Matrix:

Hmarker2world(:,:,i) = [Ri_3x3 ti_3x1;[ 0 0 0 1]] with i = number of the view, and Ri_3x3 the rotation matrix and ti_3x1 the translation vector.

Again you can set up some variables:

doShowSet doShow = 1 if you want to see what the calibration is doing
doSortHandEyeMovementSet this to 1 if you want your views sorted in a way that the interstation movement is ideal for hand-eye calibration, see [Tsai]
HandEyeMethodHere you specifiy which method you want to use for the hand-eye calibration, default is using Tsai's method. See also [3,4,5,6] and [7] for a review of those.

In order to run the calibration, type

>>handeye

Examples

For both examples set dX = dY = 2 and est_dist = [1 1 1 1 0]'

The archive also contains two examples: One is for the camera calibration only (from an endoscope with severe distortion) in order to demonstrate the abilities of coping with extreme distortions.

In order to run the example, cd to the subdirectory "example1" and start the calibration GUI (type >>calib_gui in the Matlab command prompt) and load the images. Then, type >>autocalibrate after having set the variables doShow=1 and isStronglyDistorted=1 and see the output od the calibration.

The other example shows the camera calibration, followed by the hand to eye calibration. cd to the subdirectory "example2" and again load the images using the calib_gui. Then set the variables to doShow=1 and isStronglyDistorted=0 and then type >>autocalibrate for the camera calibration. In order to launch the hand-eye calibration, load the file robot_poses.mat (load robot_poses.mat) for providing the robot-base to robot-hand transformations.

Finally, launch the hand-eye calibration (handeye) and observe the results. This example shows the ability of the grid detector to cope with extremely inhomgenous illumination and even specular reflections.

Results Example 1

Focal Length: fc = [ 385.32982 402.62202 ] ± [ 4.52279 4.50102 ]
Principal point: cc = [ 306.25515 368.80119 ] ± [ 3.35753 6.97722 ]
Skew: alpha_c = [ 0.00000 ] ± [ 0.00000 ] => angle of pixel axes = 90.00000 ± 0.00000 degrees
Distortion: kc = [ -0.39159 0.09045 -0.00118 0.00361 0.00000 ] ± [ 0.01047 0.00544 0.00480 0.00135 0.00000 ]
Pixel error: err = [ 1.04746 1.00248 ]

Results Example 2

Camera
Focal Length: fc = [ 929.95631 930.35829 ] ± [ 0.97270 0.94291 ]
Principal point: cc = [ 501.03919 383.50186 ] ± [ 0.95103 0.77064 ]
Skew: alpha_c = [ 0.00000 ] ± [ 0.00000 ]
=> angle of pixel axes = 90.00000 ± 0.00000 degrees
Distortion: kc = [ -0.12578 0.10310 -0.00374 0.00728 0.00000 ] ± [ 0.00244 0.00665 0.00021 0.00028 0.00000 ]
Pixel error: err = [ 0.16980 0.15218 ]
Hand-Eye

Backprojection error = 5.6931

It does not depend on the method you chose, all methods give the same result at the end.

Troubleshooting

I got the message that in the very first version there were missing some files, i.e. crossprod.m and rodrigues.m. The first is now part of the package, the second should be provided by the calibration toolbox from Jean-Yves, you just need to add the path to this toolbox to your matlab installation.

References

[1] http://www.vision.caltech.edu/bouguetj/calib_doc/
[2] http://www.atracsys.com
[3] Quaternion Approach to Solve The Kinematic Equation of Rotation, AaAx=AxAb, of a Sensor-Mounted Robotic Manipulator, Chou, J.C.K. and Kamel, M, Proc. IEEE Int. Conf. Robotics Automation Philadelphia, PA, pp. 656-662, Apr. 1988.
[4] Hand-Eye Calibration Using Dual Quaternions, Daniilidis K.,
[5] A New Technique for Fully Autonomous and Efficient 3D Robotics Hand-Eye Calibration, Tsai, R.Y. and Lenz, R.K, in IEEE Transactions on Robotics and Automation, Vol. 5, No. 3, 345-358, June 1989
[6] Hand-Eye Calibration, Horaud R., Dornaika F., IJRR
[7] Camera-Marker Alignment Framework and Comparison with Hand-Eye Calibration for Augmented Reality Applications, Bianchi G., Wengert C., Harders M., Cattin P., Szekely G.
[8] Fully Automatic Endoscope Calibration for Intraoperative Use, Wengert C., Reeff M., Cattin P., Szekely G.
[9] Markerless Endoscopic Registration and Referencing, Wengert C., Cattin P., Szekely G.
Additional information can be found here (Martin Bauer, Campar, TU Munich)