In [4]:
from PIL import Image
from numpy import *
from pylab import *
import numpy as np
import camera

In [2]:
# Download data from
# http://www.robots.ox.ac.uk/~vgg/data/data-mview.html
# Merton College I
# l3d, p3d, README-3D

In [3]:
Pmatrix = [loadtxt('house.'+str(i).zfill(3)+'.P').T for i in range(10)]

In [17]:
tarray = []
for P in Pmatrix:
    c = camera.Camera(P.T)
    K, R, t = c.factor()
    tarray.append(list(t))

In [18]:
print tarray


[[-0.10637505575220896, -0.0078365373533775349, 0.016957031743671854], [-1.0610255323942346, -0.050574231276840881, -0.0026970339412629683], [-1.8613224251714786, -0.14307340940555108, 0.11021617843483733], [-2.5563841251773369, -0.26617416169092173, 0.38213815077117586], [-3.2960619446817176, -0.47409099863284426, 0.78584005403771684], [-3.8908666467311797, -0.70439065458285455, 1.2123012168012604], [-4.5757350839373867, -1.0354247485919461, 1.9109318641858219], [-5.305228727462425, -1.4306469236837933, 2.927783907924415], [-5.8129308164584508, -1.8283621069536513, 3.7198497359053535], [-6.1858672391842386, -2.2658233991240846, 4.5156300797743318]]

In [20]:
points = array(tarray).T
print points


[[ -1.06375056e-01  -1.06102553e+00  -1.86132243e+00  -2.55638413e+00
   -3.29606194e+00  -3.89086665e+00  -4.57573508e+00  -5.30522873e+00
   -5.81293082e+00  -6.18586724e+00]
 [ -7.83653735e-03  -5.05742313e-02  -1.43073409e-01  -2.66174162e-01
   -4.74090999e-01  -7.04390655e-01  -1.03542475e+00  -1.43064692e+00
   -1.82836211e+00  -2.26582340e+00]
 [  1.69570317e-02  -2.69703394e-03   1.10216178e-01   3.82138151e-01
    7.85840054e-01   1.21230122e+00   1.91093186e+00   2.92778391e+00
    3.71984974e+00   4.51563008e+00]]

In [23]:
figure()
plot(points[0], points[1], 'k.')
show()



In [24]:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

In [27]:
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter3D(points[0], points[1], points[2])
show()



In [28]:
# The remaining has nothing to do with the exercise
# Move the points according to the Camera Matrix house.00n.P

points = loadtxt('house.p3d').T
points = vstack((points, ones(points.shape[1])))

In [35]:
for i in range(len(Pmatrix)):
    P = Pmatrix[i].T
    cam = camera.Camera(P)
    x = cam.project(points)
    figure()
    gray()
    im1 = Image.open('house.'+str(i).zfill(3)+'.pgm')
    imshow(im1)
    plot(x[0],x[1], 'k.')
    show()



In [ ]: