In [1]:
import numpy as np

A quiz

In [9]:
t = np.array([11,2,1])
R = np.array([0, 0, 1, 0, 1, 0, -1, 0, 0]).reshape((3,3), order='F').T
print(R)
[[ 0  0  1]
 [ 0  1  0]
 [-1  0  0]]

Write down the x, y, and z axis of the world coordinate system

In [10]:
x_world = np.array([1,0,0])
y_world = np.array([0,1,0])
z_world = np.array([0,0,1])

Write down the x, y, and z axis of the camera coordinate system (expressed in world), assuming a right-handed coordinate system

In [12]:
R_inv = np.linalg.inv(R)

x_cam = np.dot(R_inv, x_world)
y_cam = np.dot(R_inv, y_world)
z_cam = np.dot(R_inv, z_world)

print(x_cam)
print(y_cam)
print(z_cam)
[0. 0. 1.]
[0. 1. 0.]
[-1.  0.  0.]

Express the point p_world in the camera coordinate system

In [13]:
p_world = np.array([4,3,0])
p_cam = np.dot(R, (p_world - t))
print(p_cam)
[-1  1  7]

Assume that the camera principle axis is along the camera z-axis and the camera focal length is 3, express the point in image plane

In [21]:
f = 3
K = np.array([f,0,0,0,0,f,0,0,0,0,1,0]).reshape(3,4)
print(K)

p_cam_homogeneous = np.hstack([p_cam, np.array([1])])
print(p_cam_homogeneous)

p_image_homogeneous = np.dot(K, p_cam_homogeneous)
print(p_image_homogeneous)

p_image = p_image_homogeneous[:2]/p_image_homogeneous[2]
print(p_image)
[[3 0 0 0]
 [0 3 0 0]
 [0 0 1 0]]
[-1  1  7  1]
[-3  3  7]
[-0.42857143  0.42857143]
In [ ]: