QQFLY.NET
← Writing

A practical introduction to hand–eye calibration

I hadn't posted for almost a month: I was in Beijing, busy learning new things. Meanwhile, questions about hand–eye calibration kept coming in. The calibration package I'd promised was overdue and likely to stay that way for a while, so I decided to explain the principles for anyone who wanted to write their own.

I do not particularly like articles full of equations. If I cannot explain an idea in everyday language, I probably do not understand it well enough. But hand–eye calibration without any equations would look something like this:

A reaction to explaining hand–eye calibration without equations

All right. Back to the problem.

A vision system describes everything it sees in the camera's coordinate frame. For a robot to act on that information, we first need to determine the relationship between the camera and the robot. That is the hand–eye calibration problem. It is often the first obstacle a lab encounters when getting started with robotic 3D vision.

Eye-to-hand and eye-in-hand camera arrangements
Left: eye-to-hand. Right: eye-in-hand.

There are two common camera arrangements:

  • Eye-to-hand: the camera is mounted outside the arm and remains fixed relative to the robot base, or world frame.
  • Eye-in-hand: the camera is attached to the arm and moves with it.

Their equations differ slightly, but the underlying idea is similar.

Eye-to-hand: a fixed camera

A Kinect camera fixed beside the robot

Here, the Kinect is on the table beside the arm. Provided nobody moves it, its pose relative to the robot base remains fixed.

Frames and transformations for eye-to-hand calibration
A rather conspicuous watermark.

The diagram contains four coordinate frames:

  • {B}: the robot base.
  • {E}: the end link, to which the calibration board is attached.
  • {K}: the calibration board. B and C were already taken, so I picked K.
  • {C}: the camera.

The transformations between them are:

  • A: the end link's pose in the robot base frame. This comes from forward kinematics and is known; we will return to the details below.
  • B: the calibration board's pose in the end-link frame. The board was mounted in an arbitrary position, so this is unknown.
  • C: the camera's pose in the calibration-board frame. This is a camera-extrinsic calibration problem and is treated as known here; more on that shortly.
  • D: the camera's pose in the robot base frame. This is what we want, and the relationship is D=A⋅B⋅CD=A\cdot B\cdot C.

If we can determine B, D follows directly.

Two robot poses for eye-to-hand calibration

Move the arm to two poses, making sure the board is visible to the camera in both. We obtain:

The same transformation product at two poses

The board is rigidly attached to the end link, so B does not change. Rearranging gives:

Rearranging the transformations into AX = XB

This is the familiar AX = XB problem, where X is a 4×44\times4 homogeneous transformation matrix:

A 4 by 4 homogeneous transformation matrix

Searching Google Scholar for “AX=XB” turns up several ways to solve it:

Research papers on AX = XB

The papers give detailed derivations you can implement. If I have time, I'll explain one of the methods at the end.

With A, B, and C available, we can calculate our desired calibration result, D.

Eye-in-hand: a camera on the arm

A RealSense camera mounted on the end effector

In this setup, a RealSense camera is attached to the end of the arm and moves with it.

Frames and transformations for eye-in-hand calibration

The coordinate frames are the same as before. The transformations have slightly different roles:

  • A: the end link's pose in the robot base frame, again obtained from forward kinematics.
  • B: the camera's pose in the end-link frame. This relationship is fixed. Once we know it, we can calculate the camera's pose as the robot moves. B is now the quantity we want.
  • C: the camera's pose in the calibration-board frame, obtained through camera-extrinsic calibration.
  • D: the camera's pose in the robot base frame. The calibration board is removed for normal operation, so we no longer need this relationship.
Two robot poses for eye-in-hand calibration

As before, move the arm to two poses from which it can see the board, then construct the transformation loop:

The AX = XB construction for eye-in-hand calibration

And we are back to AX = XB.

See? Hand–eye calibration is easy!

Obtaining A from robot kinematics

I skipped a few details to keep the explanation clear. Let's fill them in.

A is the end link's pose in the robot base frame: a basic forward-kinematics calculation.

Robot links and their DH frames

A robotics textbook will show how to calculate it using Denavit–Hartenberg matrices or an equivalent method. In a ROS setup, tools such as KDL or TF can provide the transformation directly.

Given the current joint angles, we can calculate A.

Obtaining C from camera calibration

C describes the camera relative to the calibration board: the camera's extrinsic parameters.

Projection from 3D points to a pinhole-camera image

We typically begin with a pinhole-camera model. In the camera frame, a 3D point (X,Y,Z,1)c(X,Y,Z,1)_c and its corresponding image point (x,y)c(x,y)_c satisfy the relationship shown here:

Camera intrinsic matrix

The matrix in that expression contains the intrinsic parameters, such as focal length, which depend on the camera itself.

Usually, however, we describe objects in a world frame, (X,Y,Z,1)w(X,Y,Z,1)_w, rather than in the camera frame, whose pose we do not yet know. We therefore first transform the points from world coordinates into camera coordinates:

Transforming world coordinates into camera coordinates

This gives the complete camera model:

The camera model with intrinsic and extrinsic parameters

The task is to determine the intrinsic matrix, then use images of the calibration board at different poses to estimate the extrinsic transformation C.

In 2017, the usual choice was Zhengyou Zhang's method:

Zhang, Zhengyou. “A flexible new technique for camera calibration.” IEEE Transactions on Pattern Analysis and Machine Intelligence 22.11 (2000): 1330–1334.

Asking a beginner to implement that paper from scratch might be a little much. Fortunately, both OpenCV and MATLAB's camera-calibration toolbox provide implementations. Their documentation covers the procedure:

  • Take roughly 20 images containing the calibration board.
  • Supply the board geometry, which defines each corner's coordinates [X,Y,Z][X,Y,Z] on the board.
  • Identify the corresponding image coordinates [u,v][u,v], manually or with a corner detector.
Detected checkerboard corners
  • OpenCV or MATLAB then uses Zhang's method to estimate the camera intrinsics.
  • During robot calibration, load those intrinsics and estimate the extrinsic transformation C for each observation. OpenCV also provides the relevant functions.

Solving AX = XB

Rather than typeset another derivation, here are four papers describing different approaches:

  1. Tsai, Roger Y., and Reimar K. Lenz. “A new technique for fully autonomous and efficient 3D robotics hand/eye calibration.” IEEE Transactions on Robotics and Automation 5.3 (1989): 345–358.
  2. Horaud, Radu, and Fadi Dornaika. “Hand-eye calibration.” The International Journal of Robotics Research 14.3 (1995): 195–210.
  3. Park, Frank C., and Bryan J. Martin. “Robot sensor calibration: solving AX=XB on the Euclidean group.” IEEE Transactions on Robotics and Automation 10.5 (1994): 717–721.
  4. Daniilidis, Konstantinos. “Hand-eye calibration using dual quaternions.” The International Journal of Robotics Research 18.3 (1999): 286–298.

I tried all four. In most of my tests, their accuracy was similar, with the dual-quaternion method performing slightly better.

The papers are old, but look at the journals that published them. That gives you an idea of how much hand–eye calibration matters in robotics.

The models are approximations

I was joking when I said calibration was easy. Nearly every model we use in robotics is an approximation, and every step above has room for improvement.

First, the nominal robot model assumes away manufacturing, assembly, and control errors. Real robots do not satisfy that assumption. Calculating a pose from joint angles therefore introduces error. Identifying the robot's kinematic parameters is one way to improve the final calibration.

Second, a real camera is not an ideal pinhole camera. The mapping between spatial coordinates and pixels is nonlinear, leaving plenty of work to do on the camera model too.

Start with all these details and it's easy to get lost in them. Sometimes you have to get the big picture straight first.

Finally, a couple of animations from our own calibrations:

Eye-to-hand calibration on a Motoman SDA
Motoman SDA: eye-to-hand.
Eye-to-hand calibration on a UR5
UR5: eye-to-hand.

I was in Beijing and couldn't find an eye-in-hand demonstration on my computer.

One last practical point: it is best to choose the robot's calibration poses manually. If you generate them automatically, make sure you avoid this:

A self-collision illustrating the risk of generated calibration poses
← Writing