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
In [20]:
points = array(tarray).T
print points
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 [ ]: