Camera Calibration

What is camera calibration at all?

Camera calibration is the process of determining the intrinsic and/or extrinsic camera parameters.

The extrinsic camera parameters tell you where your camera is and where it looks to.

The intrinsic camera parameters correspond to the camera-specific properties, i.e. how it maps 3D points to 2D points.

Note that you can change e.g. the extrinsic camera parameters (moving it to another place, changing the direction it points to), while the intrinsic camera parameters would remain the same.

You can also mount two cameras at the same place and pointing into the same direction (i.e. identical extrinsic parameters), but their mapping properties can be different (i.e. intrinsic camera parameters).

Camera calibration means estimating all the parameters in the perspective camera model (← BTW: this is an execellent + very short explanation of the perspective projection).

How to calibrate a camera with OpenCV?

You can find the calibration sample program for calibrating a camera in OpenCV's samples\cpp folder.

The intrinsic camera matrix will be determined by detecting the 2D image coordinates of a known 3D object and adapting an initial intrinsic camera matrix guess such that the 3D object points are better mapped to the real measured 2D point locations.

That can best be achieved by using an object with known geometry and easily detectable feature points. OpenCV has built-in support for a chessboard as a calibration pattern.

So first we need to specify a list of calibration images in a file, e.g. my_imagelist.xml:

<?xml version="1.0"?>
<opencv_storage>
<images>
frame0005.png
frame0015.png
frame0025.png
frame0035.png
frame0045.png
...
</images>
</opencv_storage>

Then we call the calibration tool by

calibration -w 8 -h 6 -s 20 -o camparams.txt my_imagelist.xml

This tells OpenCV that the chessboard used has 9×7 fields of size 20mm each, the calibration images are listed in my_imagelist.xml and the computed camera matrix shall be written to camparams.txt.

The corners of the chessboard fields are tried to be detected for each calibration image using findChessboardCorners:

The calibration is mainly done in OpenCV's calibrateCamera2 method. Optimization is done using the Levenberg-Marquardt algorithm.

Here is the resulting camparams.txt for the calibration images above:

%YAML:1.0
calibration_time: "05/08/11 10:24:34"
image_width: 848
image_height: 480
board_width: 8
board_height: 6
square_size: 20.
aspectRatio: 1.
# flags: +fix_aspectRatio
flags: 2
camera_matrix: !!opencv-matrix
   rows: 3
   cols: 3
   dt: d
   data: [ 9.5626346845374269e+002, 0., 4.1876224310124292e+002, 0.,
       9.5626346845374269e+002, 2.4510030579151444e+002, 0., 0., 1. ]
distortion_coefficients: !!opencv-matrix
   rows: 5
   cols: 1
   dt: d
   data: [ -9.4358724806731090e-002, -1.1296806447691211e-001,
       -3.1445465663922484e-003, 4.2937678433729370e-003,
       -4.5757903445245285e-001 ]
avg_reprojection_error: 3.5234180274531735e-001

So the focal length is 956.3. But in which units is this value specified? …

In which units is the resulting focal length specified?

See this discussion about this question. Here they say:

Hi,
I think that fx = f * kx and fy = f  * ky
(and they are in pixels) if you want to have
the focal length in mm we have to multiply by the
dimensions of camera pixels :

for example if : fx = 460 and fy = 456 and we know
that the pixels dimensions are: 0.0072 mm x 0.0072mm
then f = (fx or fy) * 0.0072 = 3.312 mm 

Source code samples

 
public/camera_calibration.txt · Last modified: 2012/03/08 09:27 (external edit) · []
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki