% Homework #2

Download the functions

AxisFromRotMat.m

RotMat3D.m


% 1) Write a function that takes both
% extrinsic parameters (q Rotation matrix and x,y,z translation vector)
% and intrinsic parameters (sx, sy, u0, v0) (let f = 1)
% and returns the 3x4 homogenous projection matrix
% 2) Write a function that computes image coordinates
% from a projective matrix and a matrix of image points
% Make a projection matrix for the parameters:
t = [1 1 10]';
R =[ 0.9278 -0.36514 -0.076558;
0.35675 0.92836 -0.10427;
0.10915 0.06943 0.9916];
u0 = -0.1;
v0 = 0;
sx = 0.75;
sy = 0.75;
f = 1;
% and use this to compute the image coordinates of the cube:
vertices = [0 0 0;
1 0 0;
1 1 0;
0 1 0;
0 0 0;
0 0 1;
1 0 1;
1 0 0;
1 0 1;
1 1 1;
1 1 0;
1 1 1;
0 1 1;
0 1 0;
0 1 1;
0 0 1]';
% remember to add a row of ones (convert to homogenous coordinates)
% Use plot3 to plot the original points, and plot() for the projected points.

 

% 3) Show that a straight line in 3D projects to a straight line
% in an image, using the simplest projection model, u = f x/z, v = f y/z.

% For this problem, let f=1.
% Hint: A straight line can be defined by two points L = a*p1+(1-a)*p2),
% where a is a scalar.
% p1 = [x1,y1,z1]';
% Show that a third point on the line p3 = a*p1+(1-a)*p2
% projects to an image point (u3,v3) that can be written in the form
% u3 = b u1 + (1-b) u2
% v3 = b v1 + (1-b) v2
% where b = a*z1/(a z1 + (1-a) z2)

 

% 4) What can you do if you have two 3-D point sets with corresponding points
% that result from some unknown camera or object motion?
% Can you determine the transformation between them? A method is outlined below.

% Computing point set motions. Load Cubes.mat
% the 3D array Cubes represents a series of transformations of a homogeneous
% point set Base. You can view this series of transformations using
for j=1:5,
plot3(Cubes(1,:,j),Cubes(2,:,j),Cubes(3,:,j));
axis([0 10 0 10 5 15])
drawnow;
t0 = clock;
while etime(clock,t0)<0.3, end;
end
% each of the cube configurations Cj {where Cj = Cubes(:,:,j) }
% has been created by an unknown homogenous transformation Tj,
% such that : Cj = Tj*Base
% It is possible to use the inversion method mentioned in class to
% recover these transformations from the point set.
% Cj*Base' = Tj*(Base*Base')
% Cj*Base'*inv(Base*Base') = Tj*(Base*Base')*inv(Base*Base')
% so Tj = Cj*Base'*inv(Base*Base')
% compute Tj for each of the five Cj
% Extract the rotation axis and angle for each using
% the function AxisFromRotMat(). Plot the five axes as points in 3D using
% 3D plot. The plot should show a simple geometric figure. What is it?

% Extract the five translation vectors. Plot them as a series of 5 points.


% 5) A real camera calibration method.
% Let M denote your 3x4 projective matrix as in problem 1, and m1 denote
% the first row (m1 = M(1,:);) m2 the second, and m3 the third.
% Then u_i = m1*p_i/(m3*p_i), where '*' means matrix mult.
% v_i = m2*p_i/(m3*p_i)
% Clearing denominators, we have
% (m3*p_i)u_i = m1*p_i => -(m3*p_i)u_i + m1*p_i = 0
% (m3*p_i)v_i = m1*p_i => -(m3*p_i)v_i + m1*p_i = 0
% if we have at least 6 points, (p_1,...,p_6,...) we can find M.

% Construct a set of at least 6 points in space, and use the M matrix from problem 2
% to compute the corresponding image points [u1; v1], [u2; v2], ...


% Arrange the above equations into one big matrix equation
% Y*mu = 0
% where mu = [m1'; m2'; m3']
% and Y = [ p1' 0 0 0 0 -u1*p1';
%            0 0 0 0 p1' -v1*p1';
%                  ......
%           pn' 0 0 0 0 -un*pn';
%            0 0 0 0 pn' -vn*pn']

% Y*mu = 0 can be solved for mu using the matlab command
% mu = null(Y);
% reshape mu into the matrix M_est, and outside a scale factor (including sign)
% you should have recovered our projection matrix (e.g. M./M_est = constant)
% We can also separate the intrinsic from extrinsic parameters using
% [Q,R]=qr(M(1:3,1:3))
% In this decomposition, Q is the rotation matrix. Use this fact to extract the intrinsic
% parameters and write them down. Notice again the arbitrary scaling. However, there is a way to recover the correct scaling.
% How well does this method work?
% Comment on any errors you see (excluding the scale factor).