The camera position is defined by extrinsics and intrinsic transformations. In Kitti case the cameras can rotate and translate only respect to the world (intrinsics of a camera are supposed to be always the same since is just the car moving in the space). In short:
- camera intrinsic matrix projects the points whose coordinates are given wrt the camera onto the image plane of the camera
- camera extrinsic matrix is a change of basis matrix that converts the coordinates of a point from world coordinate system to camera coordinate system
Now consider:
c=[R|t]*w
where
c - Homogeneous coordinates of a point wrt the camera
[R|t] - Camera extrinsic matrix
w - Coordinates of a point in the world space
Starting from the data provided by kitti use the oxts package to compute the transofrmations of 6dof respect the earth.
def rotx(t):
"""Rotation about the x-axis."""
c = np.cos(t)
s = np.sin(t)
return np.array([[1, 0, 0],
[0, c, -s],
[0, s, c]])
def roty(t):
"""Rotation about the y-axis."""
c = np.cos(t)
s = np.sin(t)
return np.array([[c, 0, s],
[0, 1, 0],
[-s, 0, c]])
def rotz(t):
"""Rotation about the z-axis."""
c = np.cos(t)
s = np.sin(t)
return np.array([[c, -s, 0],
[s, c, 0],
[0, 0, 1]])
def transform_from_rot_trans(R, t):
"""Transforation matrix from rotation matrix and translation vector."""
R = R.reshape(3, 3)
t = t.reshape(3, 1)
return np.vstack((np.hstack([R, t]), [0, 0, 0, 1]))
def pose_from_oxts_packet(metadata):
"""Helper method to compute a SE(3) pose matrix from an OXTS packet.
Taken from https://github.com/utiasSTARS/pykitti
"""
lat, lon, alt, roll, pitch, yaw = metadata
scale = np.cos(lat * np.pi / 180.)
er = 6378137. # earth radius (approx.) in meters
# Use a Mercator projection to get the translation vector
ty = lat * np.pi * er / 180.
tx = scale * lon * np.pi * er / 180.
# ty = scale * er * \
# np.log(np.tan((90. + lat) * np.pi / 360.))
tz = alt
t = np.array([tx, ty, tz]).reshape(-1,1)
# Use the Euler angles to get the rotation matrix
Rx = rotx(roll)
Ry = roty(pitch)
Rz = rotz(yaw)
R = Rz.dot(Ry.dot(Rx))
return transform_from_rot_trans(R, t)
then the function call will be with the metadata read from the oxts file:
metadata = fromtxt("drive/oxts/data/0000000000.txt")
pose_matrix = pose_from_oxts_packet(metadata[:6])
Ref:
Repo kitti dataset https://github.com/utiasSTARS/pykitti