Wednesday, July 30, 2008

Activity 11 - Camera Calibration

In this activity, we captured an image of a checker board with 1 inch by 1 inch dimension of each square. These 3D object is then transform it into a 2D image by the camera. The objective of this activity is to compute the Transformation Matrix present into the camera that transforms from world to camera coordinates given by the simple equation:

Equation 1

where G is the transformation matrix, xi and yi are the image coordinates and xw, yw and zw are the world coordinates.

25 differents spots on the image (xi's and yi's) and the corresponding world coordinates of the spots (xw, yw and zw) were taken. Plugging in it into the equation given by:
Equation 2
Note: xo, yo and zo are the same as the xw, yw and zw.
Figure 1 . Image used in calibration
Note: The white dots are the points used for the calibration process and the red cross marks are the points that were predicted
The column matrix with components a is the transformation matrix.The values of a can easily be calculated by the equation:
Equation 3

where Q matrix is the leftmost matrix in Equation 2 and d matrix is the rightmost matrix in Equation 2.

The values of the transformation matrix are:

- 11.158755
16.994741
- 0.3046630
81.972117
- 4.4211357
- 3.0139446
- 19.251234
271.84956
- 0.0126526
- 0.0067189
0.0023006

To verify if the transformation matrix is correct, 12 different spots(which were not used in the calibration) from the image were then taken and predicted the location of the spots using the transformation matrix given by the equation:

Equation 4
Note: a34 is set to 1.
The results of the predicted location with comparison with the actual location using locate function in scilab is shown below:


In this activity, I will give myself a grade of 10 because the % errors I got are considerably low. I also acknowledge Abraham Latimer Camba for lending me the picture I used in this activity and Rafael Jaculbia for teaching how to use the locate function in scilab.

Appendix:
Source code in scilab


Image_mat1 = imread("F:\AP 186\activity 11\new.jpg");
gray = im2gray(Image_mat1);
imshow(gray);
Image_mat = locate(25,flag=1)';
Object_mat = fscanfMat("F:\AP 186\activity 11\Object.txt");
No = size(Object_mat);
Ni = size(Image_mat);
No2 = No(1)*2;
O = [];
for i = 1:No2
if modulo(i,2) == 1
k = ((i+1)/2);
O(i,1) = Object_mat((i+1)/2,1);
O(i,2) = Object_mat((i+1)/2,2);
O(i,3) = Object_mat((i+1)/2,3);
O(i,4) = 1;
O(i,5:8) = 0;
O(i,9) = -1*(Object_mat(k,1)*Image_mat(k,1));
O(i,10) = -1*(Object_mat(k,2)*Image_mat(k,1));
O(i,11) = -1*(Object_mat(k,3)*Image_mat(k,1));
end
if modulo(i,2)==0
O(i,5) = Object_mat(i*0.5,1);
O(i,6) = Object_mat(i*0.5,2);
O(i,7) = Object_mat(i*0.5,3);
O(i,8) = 1;
O(i,1:4) = 0;
O(i,9) = -1*(Object_mat(i*0.5,1)*Image_mat((i+1)/2,2));
O(i,10) = -1*(Object_mat(i*0.5,2)*Image_mat((i+1)/2,2));
O(i,11) = -1*(Object_mat(i*0.5,3)*Image_mat((i+1)/2,2));
end
end
d = [];
for i = 1:No2
if modulo(i,2)==1
d(i) = Image_mat(((i+1)/2),1);
end
if modulo(i,2) == 0
d(i) = Image_mat(i/2,2);
end
end

a = (inv(O'*O)*O')*d;
New_o = fscanfMat("F:\AP 186\activity 11\Object2.txt");
w = size(New_o);
y = [];
z = [];
for i = 1:w(1)
y(i) = (a(1,1)*New_o(i,1) +a(2,1)*New_o(i,2)+a(3,1)*New_o(i,3)+a(4,1))/(a(9,1)*New_o(i,1) +a(10,1)*New_o(i,2)+a(11,1)*New_o(i,3)+1);
z(i) = (a(5,1)*New_o(i,1) +a(6,1)*New_o(i,2)+a(7,1)*New_o(i,3)+a(8,1))/(a(9,1)*New_o(i,1) +a(10,1)*New_o(i,2)+a(11,1)*New_o(i,3)+1);
end

imshow(gray);
f = locate(12,flag=1);


Source:
[1] Activity manual and lectures provided by Dr. Maricor Soriano on her Applied Physics 186 class

No comments: