PinholeOptics

class dnois.optics.PinholeOptics(fl: float, sensor: Sensor = None)
forward(scene: Scene, **kwargs) Tensor

Render a scene.

Parameters:
  • scene (dnois.scene.Scene) – The scene to render.

  • kwargs – Keyword arguments passed to self.render_*_scene methods.

Returns:

Rendered image.

Return type:

Tensor

fovd2obj(fov: Sequence[tuple[float, float]] | Tensor, depth: float | Tensor, in_degrees: bool = False) Tensor

Similar to tanfovd2obj(), but computes coordinates from FoV angles rather than their tangents.

Parameters:
  • fov (Sequence[tuple[float, float]] or Tensor) – FoV angles of points in radians. A tensor with shape (..., 2) where the last dimension indicates x and y FoV angles.

  • depth (float | Tensor) – Depths of points. A tensor with any shape that is broadcastable with fov other than its last dimension.

  • in_degrees (bool) – Whether fov is in degrees. If False, fov is assumed to be in default angle unit. Default: False.

Returns:

3D coordinates of points, a tensor of shape (..., 3).

Return type:

Tensor

intrinsic(**kwargs) Tensor

Intrinsic matrix of the pinhole camera.

Parameters:

kwargs – Keyword arguments passed to torch.zeros() to construct the matrix.

Returns:

A tensor of shape (3, 3).

Return type:

Tensor

obj2fov(point: Tensor) Tensor

Similar to point2tanfov(), but returns FoV angles rather than tangents.

Parameters:

point (Tensor) – Coordinates of points. A tensor with shape (..., 3) where the last dimension indicates coordinates of points in camera’s coordinate system.

Returns:

x and y FoV angles. A tensor of shape (..., 2).

Return type:

Tensor

obj2tanfov(point: Tensor) Tensor

Converts coordinates of points in camera’s coordinate system into tangent of corresponding FoV angles:

\[\begin{split}\tan\varphi_x=-x/z\\ \tan\varphi_y=-y/z\end{split}\]

point complies with Convention for coordinates of infinite points.

Parameters:

point (Tensor) – Coordinates of points. A tensor with shape (..., 3) where the last dimension indicates coordinates of points in camera’s coordinate system.

Returns:

Tangent of x and y FoV angles. A tensor of shape (..., 2).

Return type:

Tensor

perspective(point: Tensor, flip: bool = True) Tensor

Projects coordinates of points in camera’s coordinate system to image plane in a perspective manner:

\[\left\{\begin{array}{l} x'=-\frac{f}{z}x y'=-\frac{f}{z}y \end{array}\right.\]

where \(f\) is the focal length of reference model. The negative sign is eliminated if flip is True.

Parameters:
  • point (Tensor) – Coordinates of points. A tensor with shape (..., 3) where the last dimension indicates coordinates of points in camera’s coordinate system.

  • flip (bool) – If True, returns coordinates projected on flipped (virtual) image plane. Otherwise, returns those projected on original image plane.

Returns:

Projected x and y coordinates of points. A tensor of shape (..., 2).

Return type:

Tensor

points_grid(segments: int | tuple[int, int], depth: float | Tensor) Tensor

Creates some points in object space, each of which is mapped to the center of one of non-overlapping patches on the image plane by perspective projection.

Parameters:
  • segments (int or tuple[int, int]) – Number of patches in vertical (N_y) and horizontal (N_x) directions.

  • depth (float or Tensor) – Depth of resulted points. A float or a tensor of any shape (...).

Returns:

A tensor of shape (..., N_y, N_x, 3) representing the coordinates of points in camera’s coordinate system.

Return type:

Tensor

render_image_scene(scene: ImageScene, **kwargs) Tensor

Render an image scene. Pinhole camera returns the image directly as long as its intrinsic (if exists) and resolution match those of the sensor.

Parameters:
  • scene (dnois.scene.ImageScene) – The scene to render.

  • kwargs – Not used.

Returns:

Rendered image with shape identical to that of the image of scene.

Return type:

Tensor

tanfovd2obj(tanfov: Sequence[tuple[float, float]] | Tensor, depth: float | Tensor) Tensor

Computes 3D coordinates of points in camera’s coordinate system given tangents of their FoV angles and depths:

\[(x,y,z)=z(-\tan\varphi_x,-\tan\varphi_y,1)\]

where \(z\) indicates depth. Returned coordinates comply with Convention for coordinates of infinite points.

Parameters:
  • tanfov (Sequence[tuple[float, float]] or Tensor) – Tangents of FoV angles of points in radians. A tensor with shape (..., 2) where the last dimension indicates x and y FoV angles. A list of 2-tuples of float is seen as a tensor with shape (N, 2).

  • depth (float | Tensor) – Depths of points. A tensor with any shape that is broadcastable with tanfov other than its last dimension.

Returns:

3D coordinates of points, a tensor of shape (..., 3).

Return type:

Tensor

property device: device

Device of this object.

Type:

torch.device

property dtype: dtype

Data type of this object.

Type:

torch.dtype

property fov_full: float

Full FoV of the pinhole camera:

\[\varphi_\text{full}=2\arctan\frac{L}{2f}\]

where \(L\) is diagonal length and \(f\) is focal length.

Returns:

Full FoV in radian.

Return type:

float

property fov_half: float

Half FoV of the pinhole camera:

\[\varphi_\text{half}=\arctan\frac{L}{2f}\]

where \(L\) is diagonal length and \(f\) is focal length.

Returns:

Half FoV in radian.

Return type:

float

property fov_half_x: float

Half X-FoV of the pinhole camera:

\[\varphi_\text{half-X}=\arctan\frac{W}{2f}\]

where \(W\) is the width of sensor and \(f\) is focal length.

Returns:

Half X-FoV in radian.

Return type:

float

property fov_half_y: float

Half Y-FoV of the pinhole camera:

\[\varphi_\text{half-Y}=\arctan\frac{H}{2f}\]

where \(H\) is the height of sensor and \(f\) is focal length.

Returns:

Half Y-FoV in radian.

Return type:

float

property reference: PinholeOptics

Returns the reference model of this object.

Type:

PinholeOptics

sensor: Sensor | None

The attached sensor.