Calib2GL

Calib2GL is an utility that converts camera parameters from intrinsic and extrinsic into an image plane. It is used to model real cameras with OpengGL.

The image at right is a box that's shaped just like the shelf in our lab. You can see one image plane to the right of this shelf . The red blob is the world origin.

The program. Calib2GL's source can be downloaded directly from this web site. There isn't any documentation with it however. So here are the basics.

To compile run make

This version meant to model a 2x2x2 meter working volume with a cylinder in the middle representing a human. The cylinder is 2m high and 1m in diameter. The origin is at the front bottom edge as you can see in the picture above. This should aid in measuring actual camera parameters because it is not a point floating in open space.

Calib2GL first reads a calibration file specified in the command line: calib2gl.cfg. This file specifies the input file, output file, vrpn spaceball server, and vrpn spaceball button server.

The spaceball functions work through a VRPN server running on whatever machine is connected to the spaceball. My spaceball is a 4000FLX, so it has 12 buttons, older models don't have the same number of buttons, so one should be able to modify the gain behavior differently if it doesn't work with the earlier versions. Spaceball support is a new thing to vrpn, so you need at least 6.03 Beta 3 or 4 I think. It's setup is pretty straightforward, you need to use AnalogFly, and absolute coordinates. Here's my vrpn.cfg file:

vrpn_Tracker_AnalogFly Tracker0 60.0 absolute
X *Spaceball0 0 0.0 0.0 2.0 1.0
Y *Spaceball0 1 0.0 0.0 2.0 1.0
Z *Spaceball0 2 0.0 0.0 2.0 1.0
RX *Spaceball0 3 0.0 0.0 2.0 1.0
RY *Spaceball0 4 0.0 0.0 2.0 1.0
RZ *Spaceball0 5 0.0 0.0 2.0 1.0
RESET NULL 0

vrpn_Spaceball Spaceball0 /dev/ttyS1 9600


The in program commands are as follows:

  • S: save calibration data to file
  • W: write image planes to .tiff files
  • Z: zero to camera to saved state
  • [enter] save current state
  • +: go to next camera in list
  • -: go to last camera in list
  • O: toggle origin on and off
  • C: toggle cylinder on and off
  • Q: quit
  • Spaceball Button 6: toggle translation on/off
  • Spaceball Button 5: toggle rotation on/off
  • Spaceball Button 2: increase translation gain
  • Spaceball Button 7: decrease translation gain
  • Spaceball Button 3: increase rotation gain
  • Spaceball button 8: decrease rotation gain

Next to talk about is the calibration file. I have added .cam to all of these files in order to keep some things straight. So what's in examplecameras.cam:

CameraName (this can't have any spaces)
0 0 2000 (Position of the camera in mm)
0 0 0 (Angular representation, explained later)
1358.900 1335.300 533.80 34640 (Intrinsic parameters: Sx Sy u0 v0)
50 10000 1024 768 (Intrinsic parameters: nearClip farClip width height)
(There can be blank spaces here)

First, the angular representation. Calib2GL uses Quaternion representation internally via the quatlib. But when parsing the .cam file, you can use either a quaternion or roll pitch yaw representation. That's a rotation about the x-axis, then about the y-axis, then about the z-axis (in radians).

Intrinsic parameters are represented with Sx and Sy. In Matlab's camera calibration toolbox they are fc(1) = Sx and fc(1) = Sy. Or elements (1,1) and (2,2) of the KK matrix. They are the scale factor's in both the u and v direction on the image plane. u0 and v0 are the image center for this same image plane, they are cc(1) and cc(2) or elements (1,3) and (2,3) in the KK matrix

The last line is easy. nearClip is the closest an object can be (in mm again) and still be seen, farClip is the farthest. Width and height are the size of the image plane in pixels. i.e. 1024x768.


Accuracy How accurate is this tool anyway? Well, here's some data:

This image is from my most recent version. That's where the shelf comes in.

This image isn't exactly correct. If you look closely at the right and left sides of the bookcase you can see that the left side of the virtual image is too far right, but the right edge has about the same displacement right as well. This image was taken very quickly and imprecisely because I had not tested this stuff with our new PointGray© Dragonfly camera.

The following image was a calibration image for Matlab's camera calibration toolkit. I was able to take both intrinsic and extrinsic parameter's precisely here because Matlab had calculated them.

Both images are checkerboards. They have been subtracted in Matlab. There is some radial distortion that I haven't accounted for, but otherwise the images are quite correct. This demonstrates that with two different cameras I have been able to get good image plane simulations.

Back to my home.