Assignment 2

Q1: Camera matrix P from 2D-3D correspondences (30 points)

(a) Stanford Bunny (15 points)

1- Every 2d to 3d correspondence point gives two constraints in the form:

  x, y, w = pt_2d
  X, Y, Z, W = pt_3d
  return np.array([
    [0, 0, 0, 0, -w*X, -w*Y, -w*Z, -w*W, y*X, y*Y, y*Z, y*W],
    [w*X, w*Y, w*Z, w*W, 0, 0, 0, 0, -x*X, -x*Y, -x*Z, -x*W]
  ])

2- We need 11 constraints to determine P up to scale so we need 5.5 points. However since more points were provided. We can stack more constraints and use the overdetermined solution which is selecting the right singular vector corresponding to the smallest eigen value which gives us the minimum norm solution.

3- Use P to project all 3D points.

(b) Cuboid (15 points)

Input Image:

Assuming we are looking at the zipper face. Coordinate system (Z up, X right, Y in)

Result of drawing all edges:

Q2: Camera calibration K from annotations (40 points + 10 points bonus)

(a) Camera calibration from vanishing points (20 points)

I used the same annotations as provided and got the vanishing and principal points as shown on the right.

Resulting K

K=
[[1.15417802e+03 0.00000000e+00 5.75066005e+02]
 [0.00000000e+00 1.15417802e+03 4.31939090e+02]
 [0.00000000e+00 0.00000000e+00 1.00000000e+00]]

Approach:

First step is to compute the vanishing points using simple cross products. Each parallel pair intersects in a vanishing point.

Then each pair of vanishing points gives us a constraint on the elements of w in the form of:

w1*(v11v21 + v12v22) + w2*(v11v23 + v13v21) + w3*(v12v23 + v13v22) + w4*(v13v23) = 0

Stacking 3 of these constraints we can solve for the restricted IAC w which is of the form

w =
[w1, 0 , w2],
[0 , w1, w3],
[w2, w3, w4],

The final system of equations will be Aw’= 0 where w’ = [w1, w2, w3, w4]. Then we use SVD to obtain the right null vector as the solution for w.

Once w is obtained, we use Cholesky decomposition then inversion to get K.

(b) Camera calibration from metric planes (20 points)

I used the same annotations as provided.

angle between plane 1 and 2 = 63.83
angle between plane 1 and 3 = 92.65
angle between plane 2 and 3 = 95.02

K=
[[ 1.03910950e+03 -3.14225192e+01  5.44730113e+02]
 [ 0.00000000e+00  1.07924390e+03  3.51219765e+02]
 [ 0.00000000e+00  0.00000000e+00  1.00000000e+00]]

Approach:

1- Compute homographies from square parallel to image plane (Ex. (0,0), (0,1), (1,1) (1,0) ) to the different squares to obtain three homography matrices H1, H2, H3.

2- Each homography gives us two constraints on the elements of the IAC w (hij is the the element in H at the ith row and jth column)

1-h11h12w1 + w2*(h11h22 + h12h21) + w3*(h11h32 + h12h31) + w4*(h21h22) + w5*(h21h32 + h22h31)+ w6*(h31h32)=0

2- w1*(h11**2 - h12**2) + w2*(2*h11*h21 - 2*h12*h22) + w3*(2*h11*h31 - 2*h12*h32) + w4*(h21**2 - h22**2) + w5*(2*h21*h31 - 2*h22*h32) + w6*(h31**2 - h32**2)=0

3- Stack 5 of these constraints and compute SVD and pick the right most singular vector.

4- Take inverse of cholesky decomposition to get K

6- Compute angles by computing the vanishing line for each plane and using cos(theta) = l1.T w* l2 / ( sqrt(l1.T w* l1) sqrt(l2.T w* l2) ) to compute the angle.

  • Vanishing lines are obtained by computing the two intersections of two sets of parallel lines for each square and getting the line that passes through these two vanishing points.

(c) Camera calibration from rectangles with known sizes (10 points bonus)

Q3: Single View Reconstruction (30 points + 10 points bonus)

(a) (30 points)

(b) (10 points bonus)