Thursday, July 31, 2008

A11 - Camera Calibration

July 31, 2008



In this activity, we try to align the world coordinate system, which pertains to the real three-dimensional world of an object, with the two-dimensional image coordinate system captured by a camera.


We get the transformation matrix that would translate all world coordinates to the image coordinates. This transformation matrix depends on the angle the optic axis makes with respect to the object to be captured and on the intrinsic properties of the camera which are mainly affected by its focus. Denoted by A, it can be found by first realizing that













(Equation taken from Dr. Maricor Soriano's lecture notes.)


where xo, yo, zo are real world coordinates and yi, zi are image coordinates. Thus, A is given by

A = [ (inv(Q'Q)) Q'] d

where Q is the first matrix given in equation 1 and d is the column vector at the the right hand side of the equation. When there are N sample points, Q is a 2N x 11 matrix while d has a dimension of 2N x 1.

After we have determined A, we tried to predict the image coordinates of world points that were not previously sampled. The whole process is summarized by figure 1. A celfone camera was used to capture a checkerboard with two arms positioned perpendicular to each other. Each cell in the checkerboard is 1 inch x 1 inch. Twenty-five random points and their 2D projection on the image plane were used to determine the transformation matrix. Afterwards, the position in the image of five other points were interpolated using the transformation matrix. With the z plane in the real world chosen to be vertical, the left arm was designated to be the xz plane. The right arm is then the yz plane.

We could see that the predictions are accurate since some points even blocked the labeling numbers. Prediction #2, which missed the theoretical position, is not too far from where it should be.
























Self-grade: 10/10
Credits: Benj for some clarifications on the later part of the problem


//Camera Calibration
//1 Image space
d = [135 138;230 165;177 188;229 259;178 91;279 141;261 216;110 213;244 89;159 260;179 233;135 89;315 137;36 137;63 266;64 58;315 311;63 322;317 21;39 32;38 242;180 47;336 227;88 189;297 53];
//2 Object space
s = [3.5 0 1.5;0 1.5 0.5;1.5 0 -0.5;0 1.5 -3.5;1.5 0 3.5;0 4.5 1.5;0 3.5 -1.5;4.5 0 -1.5;0 2.5 3.5;2.5 0 -3.5;1.5 0 -2.5;3.5 0 3.5;0 6.5 1.5;7.5 0 1.5;6.5 0 -3.5;6.5 0 4.5;0 6.5 -4.5;6.5 0 -5.5;0 6.5 5.5;7.5 0 5.5;7.5 0 -2.5;1.5 0 5.5;0 7.5 -1.5;5.5 0 -0.5;0 5.5 4.5];
//3 Finding the transformation matrix a
Q = zeros(50, 11);
i = 1;
j = 2*i-1;
while i<>
Q(j,1:3) = s(i,1:3);
Q(j,4) = 1;
Q(j,5:8) = 0;
Q(j,9:11) = -d(i,1)*s(i,1:3);
Q(j+1,1:4) = 0;
Q(j+1,5:7) = s(i,1:3);
Q(j+1,8) = 1;
Q(j+1,9:11) = -d(i,2)*s(i,1:3);
i = i+1;
j = 2*i-1;
end;
d = matrix(d',50,1);
a = inv(Q'*Q)*Q'*d;
//Predicting the image coordinates of unsampled world points
test = [3 0 0 1;0 5 -3 1;0 3 2 1;1 0 2 1;3 0 -2 1];
newd = a*test';
newd = matrix(newd,5,3);
newd = newd';
[m,k] = size(M);
overlay = zeros(m,k);
for i = 1:size(newd,2);
overlay(round(newd(2,i)),round(newd(1,i))) = 1;
end
M = imread('D:\ap186\july29_2008\cropped.jpg');
M = im2gray(M);
subplot(121)
imshow(M,[]);
subplot(122)
imshow(overlay);

No comments: