Wednesday, July 30, 2008

Camera Calibration

For this activity we would transform the camera coordinates into world coordinates. We used a checkerboard as the calibration object.
Since the board is placed in a 90 degree angle, I assigned the left face as the x-axis, the right face as the y-axis and the vertical axis as the z-axis. Doing this would simplify most of the equations. The origin is place bottom center of the board.
25 cornerpoints were randomly assigned. So that I would not get lost in using the locate function in Scilab, I placed markers in the image. (This would have no effect since we don't need the color information of the image) (NOTE: see code for the coordinates of the points). Each square in the board measures 1x1 inch.
In lecture 2, the camera axis is labeled as x and the image plane as yz. Since the xyz axis can be permutated without affecting the location of a point in the plane, the same derivation can be used but this time change all x with z, all y with x, and all z with y.
To solve for the camera parameters, we used the following equation:
Labeling the first matrix as Q, the second as a (camera parameters), and the third as d (image plane coordinates), we get:
//Scilab code
image = imread("cboard-marked-gs.bmp") - 1;

imshow(image, [])
d = locate(25, flag = 1);

coords = [0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 2 3 3 4 5 5 6 6 6; //x

1 1 2 2 3 4 4 4 4 5 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0; //y

2 6 4 7 5 1 3 6 9 7 3 5 1 3 5 8 6 2 8 4 2 7 1 4 9]; //z

Q = [];

for i = 1:25

x = coords(1, i);
y = coords(2, i);

z = coords(3, i);

yi = d(1, i);

zi = d(2, i);

Qi = [x y z 1 0 0 0 0 -(yi*x) -(yi*y) -(yi*z);

0 0 0 0 x y z 1 -(zi*x) -(zi*y) -(zi*z)];

Q = cat(1, Q, Qi);

end

d = matrix(d, [length(d), 1]);
a = inv(Q'*Q)*Q'*d

//end of code


The computed camera parameters are:
-19.387751
9.411270
-0.564041
172.318473
-2.744767
-3.956096
20.590540
36.630648
-0.008846
-0.013345
-0.001769

To this if this calibration is correct, I first tried to convert the object coordinate to image coordinate using the camera calibration above and the following equation:
//Scilab code
a = [-19.387751 ;9.411270 ;-0.564041 ;172.318473 ;-2.744767 ;-3.956096 ;
20.590540 ;36.630648 ;-0.008846 ;-0.013345 ;-0.001769 ]
coords = [0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 2 3 3 4 5 5 6 6 6;
1 1 2 2 3 4 4 4 4 5 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0;
2 6 4 7 5 1 3 6 9 7 3 5 1 3 5 8 6 2 8 4 2 7 1 4 9];
yi = []
zi = []
for i = 1:6
x = coords(1, i);
y = coords(2, i);
z = coords(3, i);
yi(i) = (a(1)*x + a(2)*y + a(3)*z + a(4))/(a(9)*x + a(10)*y + a(11)*z + 1);
zi(i) = (a(5)*x + a(6)*y + a(7)*z + a(8))/(a(9)*x + a(10)*y + a(11)*z + 1);
end
d = cat(2, yi, zi);
//end of code

After processing all the coordinates used, the deviations from using the locate function of scilab and this equation are:
Tables

yi zi
0.52826 0.87672
0.87410 0.22682
0.15622 0.77860
0.83752 0.86413
0.84163 0.82441
0.64452 0.62763
0.89180 1.10098
0.33847 0.09812
0.41275 0.15379
0.37815 0.40735
0.66961 0.21872
0.87220 0.29042
0.83183 0.46501
0.87415 1.30520
0.98954 0.23742
0.01032 0.98742
1.06601 0.00136
0.50450 0.61056
0.42662 0.28194
0.77159 0.11263
0.87657 0.02865
0.11396 1.14443
1.33988 0.06806
0.99433 1.24125
0.22386 0.0234

Tables
Tables Tables The mean is 0.659 and 0.519 for yi and zi respectively with standard deviation equal to 0.335 and 0.425. This translates to less than 2% error for all the values computed.
Using the camera parameters obtained, I tried predicting the image coordinates of some unused cornerpoints. The results are as follows:
Tables

Predicted
Located
Difference
171.537 98.9273
172.187 98.9699
0.650 0.043
183.460 96.2413
186.133 95.1664
2.674 1.075
208.713 47.3315
209.588 47.6228
0.875 0.291
153.706 76.0082
155.705 76.4342
1.999 0.426
135.287 73.8909
135.42 75.5151
0.133 1.624
115.791 114.611
115.135 113.550
0.657 1.061

Tables The predictions were quite accurate.

For this activity, I give myself a grade of 10 because the results I obtained were precise and accurate.
Thanks to Cole Fabros for some clarifications on the needed equations
Collaborators: Raf Jaculbia
Tables

1 comment: