Assignment 2

Andrew ID: bjhamb

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

Bunny:

Calculated Matrix P:


	 [ 6363.7512755  -2857.91004589  1238.41308267  2227.47152199]
	 [-1013.06892585 -6724.20242552  2137.74831366  1824.17003515]
	 [    0.53358345    -1.37704085    -0.69822705     1.        ]
Original Image
Annotated Image
Projected Points

Cuboid

Computed P

[ 162.23534225   75.19758457  -39.84539248  708.00144083]
 [   8.78359361  -11.27977983 -173.13125277 1785.80830353]
 [   0.00423805    0.0430678    -0.02390775    1.        ]
Projected Bounding Box
Original Image
Annotated Image

I sampled 3d points within cuboid and projected them to the image, here is the visualization

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

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

Provided Annotations:

Recovered Camera Intrinsics Matrix (K):

 [1154.17801827    0.          575.06600499]
 [   0.         1154.17801827  431.93909042]
 [   0.            0.            1.        ]
Original Image
Annotated Lines
Principal point (red dot)

Vanishing Points

Custom Annotations

Recovered K:

 [1002.45084201    0.          733.63881232]
 [   0.         1002.45084201  528.95733584]
 [   0.            0.            1.        ]

The recovered K is a bit different from the K found above, indicating that results are sensitive to the annotations

Original Image

Principal Point (red dot)
Annotated Image
Vanishing Points

Implementation Steps

  1. Find Vanishing Points
    We are provided 3 pairs of parallel lines, all of which are perpendicular to each other.
    • For each pair, extract parallel lines from gives points, line passing through points p1p_1 and p2p_2 can be found using l1=p1×p2l_1 = p_1 \times p2 and l2=l1=p3×p4l_2 = l_1 = p_3 \times p4. Find Intersection point of pair of parallel lines using v=l1×l2v = l_1 \times l_2. This is the vanishing point for the direction corresponding to the parallel lines
    • Repeat the above to find the 3 vanishing points v1,v2,v3v_1, v_2, v_3

  1. Find the Image of absolute conic (ω\omega)

    Since ω\omega  is a symmetric matrix, we can write it as:

    ω=[abcbdecef]\omega = \begin{bmatrix} a & b & c \\ b & d & e \\ c & e & f \end{bmatrix}

    As we are given that the pixels are square and have 0 skew     \impliesa=d and b=0

    ω=[a0c0aecef]\omega = \begin{bmatrix} a & 0 & c \\ 0 & a & e \\ c & e & f \end{bmatrix}

    Thus ω\omega  has 3 degrees of freedom (4-1(for scale ambiguity)) and we need 3 constraints to find it.

    Since all three vanishing are orthogonal to each other, for any pair (vi,vj)(v_i, v_j) we can say

    viTωvj=0v_i^{T}\omega v_j = 0
    [vi0vj0+vi1vj1vi0vj2+vi2vj0vi1vj2+vi2vj1vi2vj2][abcd]=0\begin{bmatrix} v_{i0}v_{j0} + v_{i1}v_{j1} & v_{i0}v_{j2} + v_{i2}v_{j0} & v_{i1}v_{j2} + v_{i2}v_{j1} & v_{i2}v_{j2} \end{bmatrix} \begin{bmatrix} a \\b \\ c\\d\end{bmatrix} = 0

    Thus each pair adds 1 constraint on the iac, and three pairs provide the 3 constraints needed to find ω\omega. We can stack each constraints to get an equation of the form

    Ac=0Ac=0

    c (and hence can be found as the right singular vector of A

  1. Find K from ω\omega

    Since ω=KTK1\omega = K^{-T}K^{-1}

    We can do cholesky decomposition to get ω=LLT\omega = LL^{T}

    Thus K would be K=LTK = L^{-T}

    Principle point would just be (K[0,2], K[1,2])

b) Camera calibration from metric planes (20 points)

Original Image
Annotated Plane 1
Annotated Plane 2
Annotated Plane 3

Recovered K:

 [1076.92614406   -4.52638065  511.56892341]
 [   0.         1076.26752438  395.52627813]
 [   0.            0.            1.        ]
Angle between planes 0 and 1: 67.2824252644341
Angle between planes 1 and 2: 92.20348558861174
Angle between planes 2 and 3: 94.71069301662284

Implementation Steps:

  1. For each metric plane, identify homography that transforms a metric square (A square with coordinates {(0,1), (1,1), (1,0), (0,0)} to the annotated squares.
  1. Each such homography provides 2 constraints.
    • If H=(h1,h2,h3)H = (h_1, h_2, h_3) where (h1,h2,h3)(h_1, h_2, h_3) are columns of H, then :
    h1Tωh2=0h_1^T \omega h_2 = 0
h1Tωh1=h2Tωh2h_1^T \omega h_1 = h_2^T \omega h_2

If h1T=[x1,x2,x3]h_1^T = [x_1, x_2, x_3] and h2T=[y1,y2,y3]h_2^T = [y_1, y_2, y_3] then the constraints can be written as

If ω=[abcbdecef]\omega = \begin{bmatrix} a & b & c \\ b & d & e \\ c & e & f \end{bmatrix}

[x1x2x1y2+y1x2x1w2+w1x2y1y2y1w2+w2y1w1w2x12x222(x1y1x2y2)2(x1w1x2w2)y12y222(y1w1y2w2)w12w22][abcdef]=0\begin{bmatrix} x_1 x_2 & x_1y_2 + y_1x_2 & x_1 w_2 + w_1 x_2 & y_1 y_2 & y_1 w_2 +w_2y_1 & w_1 w_2 \\ x_1^2-x_2^2 & 2(x_1y_1-x_2y_2) & 2(x_1w_1-x_2w_2) & y_1^2-y_2^2 & 2(y_1w_1-y_2w_2) & w_1^2-w_2^2 \end{bmatrix} \begin{bmatrix} a \\ b \\ c \\ d \\ e \\ f \end{bmatrix} = 0

Thus each pair adds 2 constraint on the iac, and three pairs provide the 6 constraints needed to find ω\omega. We can stack each constraints to get an equation of the form

Ac=0Ac=0

c (and hence can be found as the right singular vector of A

  1. Find K from ω\omega

    Since ω=KTK1\omega = K^{-T}K^{-1}

    We can do cholesky decomposition to get ω=LLT\omega = LL^{T}

    Thus K would be K=LTK = L^{-T}

  1. Find angles
    • Find normals to each plane

      For each plane, identify 2 pairs of parallel lines, find intersection of each pair to find the vanishing points. Each vanishing point gives a direction and we can find normal to the plane by taking cross product of the 2 directions.

      Say vanishing points are (v1,v2)(v_1, v_2) then:

      d1=K1v1d2=K1v2normal=d1×d2d_1 = K^{-1}v_1 \\ d_2 = K^{-1}v_2 \\ normal = d_1 \times d_2

    Then to find angle between 2 planes, we can simply find angle between their normals

    cos(θ)=n1Tn2n1Tn1n2Tn2cos(\theta) = \frac{n_1^Tn_2}{\sqrt{n_1^Tn_1*n_2^Tn_2}}

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

Original Image
Annotated Plane 2
Annotated Plane 1
Annotated Plane 3

Recoverd K

 [3142.59911967 -438.70165602 2876.60285282]
 [   0.         3073.06738741 2157.30593526]
 [   0.            0.            1.        ]
Angle between planes 0 and 1: 63.89607900586695
Angle between planes 1 and 2: 24.173714486301964
Angle between planes 2 and 3: 39.9442024479043

Implementation Steps:

The steps are same as the previous question. The only difference is the vertices plane from which homography is calculated. Instead of being a metric plane now it is a rectangle with coordinates

width = 1
height = width * height*height_width_ratio
Vertices: [[0, height], [width, height], [width, 0], [0, 0]]

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

Implementation Steps:

Recovered K:

 [809.95140903   0.         510.72008772]
 [  0.         809.95140903 356.2689548 ]
 [  0.           0.           1.        ]

Original Image
Reconstructed view - angle 1
Reconstructed view - angle 2

(b) (10 points bonus)