Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Assignment 2 solution , Exercises of Computer Vision

it is the solution of assignment 2

Typology: Exercises

2017/2018

Uploaded on 02/14/2018

hafiz_arslan
hafiz_arslan 🇬🇧

2 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Sample'Solution'for'Assignment'2'
!
Problem(2b(
!
i. To!generate!a!set!of!100!planar!points!on!a!randomly!oriented!plane,!I!have!used!two!different!approaches.!!
!
Method!1:!Find!three!points!on!the!randomly!oriented!plane!as!the!null!vector!of!plane!parameters,!and!then!
interpolate!between!them.!This!method!is!discussed!in!lecture!slides.!
!
n = 100;
%% create points on plane
% choose random plane
p = rand(4,1);
%choose points on plane
X = null(p') * [rand(2,n); ones(1,n)];
%convert to inhomogeneous form and plot
X = X ./ [X(4, :)' * ones(1,4)]';
plot3(X(1,:), X(2,:), X(3,:), '.');
Note!that!!
a) The!plane!is!chosen!randomly.!!
b) All!points!are!generated!in!a!3xn!or!a!4xn!format.!In!this!way,!each!point!is!a!vector!and!all!vectors!can!be!
transformed!in!one!go.!
c) The!conversion!to!inhomogeneous!form!is!done!in!a!single!line!for!all!the!points.!This!code!snippet!is!slightly!
tricky!but!quite!compact!and!handy.!
The!figure!which!is!generate!it!the!following:!
!
!
If!I!rotate!this!figure,!I!can!get!it!to!a!viewpoint!that!shows!that!the!points!are!on!a!plane.!!
!
!
!
To!verify!algebraically!that!the!points!are!indeed!on!a!plane,!I!can!compute!their!dot!product!with!the!plane!
parameters.!It!should!come!out!to!be!zero,!
!
!
pf3
pf4

Partial preview of the text

Download Assignment 2 solution and more Exercises Computer Vision in PDF only on Docsity!

Sample Solution for Assignment 2

Problem 2b

i. To generate a set of 100 planar points on a randomly oriented plane, I have used two different approaches. Method 1: Find three points on the randomly oriented plane as the null vector of plane parameters, and then interpolate between them. This method is discussed in lecture slides. n = 100; %% create points on plane % choose random plane p = rand(4,1); %choose points on plane X = null(p') * [rand(2,n); ones(1,n)]; %convert to inhomogeneous form and plot X = X ./ [X(4, :)' * ones(1,4)]'; plot3(X(1,:), X(2,:), X(3,:), '.'); Note that a) The plane is chosen randomly. b) All points are generated in a 3xn or a 4xn format. In this way, each point is a vector and all vectors can be transformed in one go. c) The conversion to inhomogeneous form is done in a single line for all the points. This code snippet is slightly tricky but quite compact and handy. The figure which is generate it the following: If I rotate this figure, I can get it to a viewpoint that shows that the points are on a plane. To verify algebraically that the points are indeed on a plane, I can compute their dot product with the plane parameters. It should come out to be zero,

sum(p'*X) ans =

  • 1.0922e- 14 which is indeed very small and practically zero. Method 2: An alternate method is to generate points on Z =0 plane and then rotate and translate them arbitrarily. % generate points on Z=0 plane; X = [rand(2,n); zeros(1,n)]; %generate random rotation [R, S, V] = svd(rand(3)); if det(R) == - 1 R([2 3], :) = R([3 2],:); end; %transform points with the above rotation and random translation X = R * X + 100 * rand(3,1) * ones(1,n); %plot in 3D plot3(X(1,:), X(2,:), X(3,:), '.'); Note that a) I used SVD of a random 3x3 matrix to get an orthonormal matrix, and then verified its determinant to make sure that it is a rotation matrix. b) The translation vector is added to all points in one go, by replicating the vector n times by outer product with ones(1,n). This method also generates nicely distributed random points on a plane. ii. To create an arbitrary camera, I used the following code snippet. [R, temp] = qr(rand(3)); if det(R) == - 1 R([2 3], :) = R([3 2],:); end; K = [rand * eye(2) rand(2,1); 0 0 1]; P1 = K * R * [eye(3) rand(3,1)]; The rotation matrix is generated by getting an orthonormal matrix from QR decomposition, and checking its determinant to ensure that it does not include a reflection. The intrinsic matrix is generated by having a random focal length value on the diagonal and a random principal point. A random translation vector is added. The same code snippet is repeated to generate another camera. iii. To project points into the cameras, I used the following script: iv. x1 = P1 * X; x1 = x1 ./ [x1(3,:)' * ones(1,3)]';

The error for a particular run comes out to be 3.0048e- 15 , which is practically zero. Since the whole script is written in a generic fashion, I can run it several times to compute the error. I ran this script 1000 times. The average error that I got was 3.0353e- 09 , with max as 1.2128e- 06 and min as 5.5584e- 16. It turns out that most of the time, the error is very low (median 4.3848e- 14 ), but a few times, the error comes out to be high, so the mean is relatively high. Nevertheless, even in the worst case, the error is of the order of 1e- 06 , which shows that the points are indeed representable by a homography. The plot of the error graph is given below for 1000 runs. To investigate what causes the error to be abnormally high in some cases, I put a conditional break-­‐point, to pause the code when error is greater than 1e-­‐08. The next time I ran the code, sure enough, I hit the break-­‐point on 98th^ iteration, with an error of 4.3777e-­‐08. Upon investigation, it was revealed that in this case, the points came to be mapped almost to a line. The SVD of H showed that the three singular values were 8.06, 0.42, 0.0046. With the third value being about 1000 times smaller than the first value, the matrix is ill conditioned. Since I chose everything randomly, such a case can occur, which yields larger error than expected. However, as shown above, this case occurs infrequently.