Camera Orientation

Tip

Projections transforms from the camera to the space coordinate system. Parameters are \(\alpha_\mathrm{tilt}, \alpha_\mathrm{roll}, \alpha_\mathrm{heading}\) and the position \(x,y,z\).

Most cameras are not just heading down in z direction but have an orientation in 3D space. Therefore, the module spatial allows to transform from camera coordinates (3D, origin at the camera, z=distance from camera) to the space coordinates (3D, camera can have an arbitrary orientation).

Parameters

  • heading_deg, \(\alpha_\mathrm{heading}\): the direction in which the camera is looking. (0°: the camera faces “north”, 90°: east, 180°: south, 270°: west)
  • tilt_deg, \(\alpha_\mathrm{tilt}\): the tilt of the camera. (0°: camera faces down, 90°: camera faces parallel to the ground, 180°: camera faces upwards)
  • roll_deg, \(\alpha_\mathrm{roll}\): the rotation of the image. (0°: camera image is not rotated (landscape format), 90°: camera image is in portrait format, 180°: camera is in upside down landscape format)
  • pos_x_m, \(x\): the x position of the camera.
  • pos_y_m, \(y\): the y position of the camera.
  • elevation_m, \(z\): the z position of the camera, or the elevation above the xy plane.

Transformation

class CameraTransform.SpatialOrientation(elevation_m=None, tilt_deg=None, roll_deg=None, heading_deg=None, pos_x_m=None, pos_y_m=None)[source]

The orientation can be represented as a matrix multiplication in projective coordinates. First, we define rotation matrices around the three angles: tilt, roll, heading:

\[\begin{split}R_{\mathrm{roll}} &= \begin{pmatrix} \cos(\alpha_\mathrm{roll}) & \sin(\alpha_\mathrm{roll}) & 0\\ -\sin(\alpha_\mathrm{roll}) & \cos(\alpha_\mathrm{roll}) & 0\\ 0 & 0 & 1\\ \end{pmatrix}\\ R_{\mathrm{tilt}} &= \begin{pmatrix} 1 & 0 & 0\\ 0 & \cos(\alpha_\mathrm{tilt}) & \sin(\alpha_\mathrm{tilt}) \\ 0 & -\sin(\alpha_\mathrm{tilt}) & \cos(\alpha_\mathrm{tilt}) \\ \end{pmatrix}\\ R_{\mathrm{heading}} &= \begin{pmatrix} \cos(\alpha_\mathrm{heading}) & -\sin(\alpha_\mathrm{heading}) & 0\\ \sin(\alpha_\mathrm{heading}) & \cos(\alpha_\mathrm{heading}) & 0\\ 0 & 0 & 1\\ \end{pmatrix}\end{split}\]

These angles correspond to ZXZ-Euler angles.

And the position x, y, z (=elevation):

\[\begin{split}t &= \begin{pmatrix} x\\ y\\ \mathrm{elevation} \end{pmatrix}\end{split}\]

We combine the rotation matrices to a single rotation matrix:

\[\begin{split}R &= R_{\mathrm{roll}} \cdot R_{\mathrm{tilt}} \cdot R_{\mathrm{heading}}\\\end{split}\]

and use this matrix to convert from the camera coordinates to the space coordinates and vice versa:

\[\begin{split}x_\mathrm{camera} = R \cdot (x_\mathrm{space} - t)\\ x_\mathrm{space} = R^{-1} \cdot x_\mathrm{space} + t\\\end{split}\]
SpatialOrientation.cameraFromSpace(points)[source]

Convert points (Nx3) from the space coordinate system to the camera coordinate system.

Parameters:points (ndarray) – the points in space coordinates to transform, dimensions (3), (Nx3)
Returns:points – the points in the camera coordinate system, dimensions (3), (Nx3)
Return type:ndarray

Examples

>>> import CameraTransform as ct
>>> orientation = ct.SpatialOrientation(elevation_m=15.4, tilt_deg=85)

transform a single point from the space to the image:

>>> orientation.spaceFromCamera([-0.09, -0.27, -1.00])
[0.09 0.97 15.04]

or multiple points in one go:

>>> orientation.spaceFromCamera([[-0.09, -0.27, -1.00], [-0.18, -0.24, -1.00]])
[[0.09 0.97 15.04]
 [0.18 0.98 15.07]]
SpatialOrientation.spaceFromCamera(points, direction=False)[source]

Convert points (Nx3) from the camera coordinate system to the space coordinate system.

Parameters:
  • points (ndarray) – the points in camera coordinates to transform, dimensions (3), (Nx3)
  • direction (bool, optional) – whether to transform a direction vector (used for the rays) which should just be rotated and not translated. Default False
Returns:

points – the points in the space coordinate system, dimensions (3), (Nx3)

Return type:

ndarray

Examples

>>> import CameraTransform as ct
>>> orientation = ct.SpatialOrientation(elevation_m=15.4, tilt_deg=85)

transform a single point from the space to the image:

>>> orientation.spaceFromCamera([0.09 0.97 15.04])
[-0.09 -0.27 -1.00]

or multiple points in one go:

>>> orientation.spaceFromCamera([[0.09, 0.97, 15.04], [0.18, 0.98, 15.07]])
[[-0.09 -0.27 -1.00]
 [-0.18 -0.24 -1.00]]