LAB 7
CAMERA CALIBRATION
Source Code
|
|
|
|
|
|| Lab2 ||
Lab3 ||
Lab4 ||
Lab5 ||
Lab6 ||
Lab7 ||
Lab8 ||
Back to Main Menu
________________________________________________________________________________________________________________________
Aim of this lab:
The aim of this laboratory involves finding the
relationship between 3D world coordinates and their 2D projected positions in
the images.
________________________________________________________________________________________________________________________
The two images below stereo1.jpg (Figure2) and stereo2.jpg (Figure3) are images with views of a calibration target. The XYZ coordinates of the target points are available in calibpts.m. These points are defined with respect to a coordinate frame having its origin at the base of the calibration target as shown in Figure1. This image also shows the numbering of the points.
Figure1: Image with order of points

Figure2: stereo2.jpg
Figure3:
stereo2.jpg
We were asked to write a function to
perform the camera calibration that is calibrate.m. We know that camera calibration involved finding the
relationship between 3D world coordinates and their 2D projected positions in
the image. To find the 2D image coordinates of these 3D world coordinates, we
use the Matlab function ginput to digitise the points according to the order
shown in Figure1. The result of this operation will return an array of
the form [u, v] where u is the column and v is the row of each point in the
image.
We then convert this array into a vector by using the Matlab's matrix
concatenation syntax which is uv = [uv];
After that, we need to set up the matrix
equation that needs to be solved. This is done in the
calibrate.m. The equation
set up will be in the form of :
BC = UV
where:
B is a 2n x 11 matrix of constraint coefficients
C is an 11 element column vector of calibration matrix coefficients to be
solved, and
UV is a 2n column vector of the image coordinates of the target points.
We then need to solve the equation :
C = B \ UV
This matrix equation is overstrained, therefore Matlab will perform a QR
decomposition on the matrix B in order to solve the least squares solution.
The function we have written that is calibrate.m
will display the original image and plots the digitised point. It also projects
the XYZ coordinates back into image coordinates using the calibration matrix.
Besides that, the mean square error between the position of the uv coordinates
and the projected XYZ coordinates for both images, as well as the error in
satisfying the matrix calibration constraints will also be computed by running
this function.
With the arbitrary scale of the camera
calibration matrix, the main measure of the error in satisfying the camera
matrix constraint is the value of :
(q1 x q3) . (q2 x q3)
This quantity represents the scaled cosine of the angle between the vectors (q1 x q3) and (q2 x q3), which should be perpendicular. To get a value that represents a pure (unscaled) cosine it should be divided by the magnitude of |q1 x q3| and the magnitude of |q2 x q3| in order get the dot product between two unit vectors, and hence the cosine.
The mean square error computed by the
calibrate.m function here simply uses the
value of the pure (unscaled) cosine and divided by the size of XYZ
Mean Square Error = (q1^q3) . (q2^q3) / |q1^q3| *
|q2^q3| * 1 / size of XYZ
The results on executing the function are shown as follows:
MATLAB Command:
im1 = imread('stereo1.jpg');
%upload stereo1.jpg
im2 = imread('stereo2.jpg');
%upload stereo2.jpg
show(im1);
[u1 v1] = ginput(12);
%digitise 12 points in
the image
uv1 = [u1 v1];
%Matlab's concatenation
syntax
C1 = calibrate(im1,calibPts,uv1)
%get the calibration of the
image
show(im2);
[u2 v2] = ginput(12);
uv2 = [u2 v2];
C2 = calibrate(im2,calibPts,uv2)

Figure4:
stereo1.jpg after performing camera calibration
Figure5:
stereo2.jpg after performing camera calibration
Result on Stereo1:
1. The calibration matrix of stereo1.jpg computed from Matlab is :
C1 =
0.6764
-0.7124 -0.0357 363.2515
-0.1870
-0.1191 -0.9485 345.2300
0.0006
0.0004 -0.0002 1.0000
2. The mean squared
error is :
9.808799e-004
3. The error in satisfying
the camera calibration matrix constraint is :
5.922717e-009
4.
(q1^q3).(q2^q3)/|q1^q3|*|q2^q3| =
1.177056e-002
Result on Stereo2:
1. The calibration matrix of stereo1.jpg computed from Matlab is :
C2 =
0.8825 -0.2267 -0.0265 347.8914
-0.0881
-0.2265 -0.9133 339.0455
0.0001 0.0004 -0.0002 1.0000
2. The mean squared
error is :
1.536226e-004
3. The error in satisfying
the camera calibration matrix constraint is :
3.515452e-010
4.
(q1^q3).(q2^q3)/|q1^q3|*|q2^q3| =
1.843471e-003
After obtaining the results, we then save the result and store
in a file called mydata.mat by using Matlab's save command as follows:
save mydata im1 im2 calibPts uv1 uv2 C1 C2
This will save the variables
im1, im2, calibPts, uv1 , uv2 , C1 and C2 in a file called mydata.mat. These
information will be needed for Lab 8.

Written
by Geoffrey Liau
Last updated: 23rd May 2005
liauc01@student.uwa.edu.au