Sunday, February 14, 2010

[Activity] 6 : Camera Calibration

Activity 6 : Camera Calibration

For this activity, we try to extract the intrinsic and extrinsic characteristics of a camera. Even if two cameras are of the same brand and model, their characteristics still differ minutely. We extract these characteristics by utilizing two boards with a pattern similar to chess board, the first being a single plane board and the second having a 90-degree angle in the middle of the board. The latter board is called the Tsai board, named from Roger Tsai. These two boards are shown below.

Boards used to calibrate the camera, (left) planar and (right) Tsai

I. Using a folded checkboard (Tsai Board)

Using the Tsai board and a predefined axis, we sample pixels in the Tsai board image that corresponds to the square corners. The result will be a matching between the coordinates of the corner pixels and the coordinates of the defined axis. The values will then be used in the following equation:

Equation relating the image pixel coordinates to the
defined (x,y,z) coordinates

The vector of a's can be computed by using the following equation.

Equation to solve for vector 'a'

The vector a represents the intrinsic and extrinsic characteristics of the camera. Using these values, we could predict any other point in the image by using the following formula:

Equations to predict other image coordinates xi's and yi's

The following shows the input and output of this part of the activity. In the left image, the green crosshairs shows the corners that have been selected to compute for the intrinsic/extrinsic characteristics of the camera. The image on the right shows that the other corners have been properly predicted.


(Left) Selected points and (Right) Rest of the points properly predicted.


II. Using a camera calibration toolbox

Using the camera calibration toolbox, instead of specifying many square corners, we only need to specify the four cornermost points in the planar board and let the program detect the lines and corners of the image. Aside from the corners, the program also detects if warping is present.
The following images show the board with the corners detected.





And most importantly, the program computed the intrinsic and extrinsic characteristics as shown below.

Calibration values as computed by the Calibration Toolbox



Code Listing
function tsaiboard
board = imread('tsai.jpg');
figure,imshow(board);
xi = [];
yi = [];
xyz = [];
for ytemp=0:2:10
xyz = [xyz ; [0 ytemp 0]];
disp([0 ytemp 0]);
[x, y] = ginput;
xi = [xi x(end)];
yi = [yi y(end)];
end
for ytemp=0:2:10
for xz=1:2:7
xyz = [xyz ; [xz ytemp 0]];
disp([xz ytemp 0]);
[x, y] = ginput;
xi = [xi x(end)];
yi = [yi y(end)];
end
for xz=1:2:7
xyz = [xyz ; [0 ytemp xz]];
disp([0 ytemp xz]);
[x, y] = ginput;
xi = [xi x(end)];
yi = [yi y(end)];
end
end
save 'coords.mat';

load coords.mat;
Q = [];
p = [];
for i=1:1:size(xyz, 1)
currentxyz = xyz(i,:);
currentQ = [currentxyz 1 0 0 0 0 -(xi(i)*currentxyz(1)) -(xi(i)*currentxyz(2)) -(xi(i)*currentxyz(3)); 0 0 0 0 currentxyz 1 -(yi(i)*currentxyz(1)) -(yi(i)*currentxyz(2)) -(yi(i)*currentxyz(3))];
% pause
Q = [Q; currentQ];
p = [p; xi(i); yi(i)];
end
A = inv(Q'*Q)*Q'*p
save coords.mat;

figure, imshow(imread('tsai.jpg'));
hold
for ytemp=0:1:10
for xz=1:1:7
xi = round((A(1)*xz + A(2)*ytemp + A(3)*0 + A(4))/(A(9)*xz + A(10)*ytemp + A(11)*0 + 1));
yi = round((A(5)*xz + A(6)*ytemp + A(7)*0 + A(8))/(A(9)*xz + A(10)*ytemp + A(11)*0 + 1));
disp([xi yi]);
plot(xi, yi, '+', 'color', 'green');
end
for xz=1:1:7
xi = round((A(1)*0 + A(2)*ytemp + A(3)*xz + A(4))/(A(9)*0 + A(10)*ytemp + A(11)*xz + 1));
yi = round((A(5)*0 + A(6)*ytemp + A(7)*xz + A(8))/(A(9)*0 + A(10)*ytemp + A(11)*xz + 1));
disp([xi yi]);
plot(xi, yi, '+', 'color', 'green');
end
end

I give myself a grade of 8.5 for this activity for successfully accomplishing the objectives. However, I could not compare the extrinsic/intrinsic values of the camera for both methods. I don't know which variables to compare.

References:
[1] Activity 6: Camera Calibration Activity Sheet, Maricor Soriano
[2] Camera Calibration Toolbox, Available: http://www.vision.caltech.edu/bouguetj/calib_doc/

No comments:

Post a Comment