tensorbay.sensor.sensor

SensorType, Sensor, Lidar, Radar, Camera, FisheyeCamera and Sensors.

SensorType is an enumeration type. It includes ‘LIDAR’, ‘RADAR’, ‘CAMERA’ and ‘FISHEYE_CAMERA’.

Sensor defines the concept of sensor. It includes name, description, translation and rotation.

A Sensor class can be initialized by Sensor.__init__() or Sensor.loads() method.

Lidar defines the concept of lidar. It is a kind of sensor for measuring distances by illuminating the target with laser light and measuring the reflection.

Radar defines the concept of radar. It is a detection system that uses radio waves to determine the range, angle, or velocity of objects.

Camera defines the concept of camera. It includes name, description, translation, rotation, cameraMatrix and distortionCoefficients.

FisheyeCamera defines the concept of fisheye camera. It is an ultra wide-angle lens that produces strong visual distortion intended to create a wide panoramic or hemispherical image.

Sensors represent all the sensors in a FusionSegment.

class tensorbay.sensor.sensor.SensorType(value)[source]

Bases: tensorbay.utility.type.TypeEnum

SensorType is an enumeration type.

It includes ‘LIDAR’, ‘RADAR’, ‘CAMERA’ and ‘FISHEYE_CAMERA’.

Examples

>>> SensorType.CAMERA
<SensorType.CAMERA: 'CAMERA'>
>>> SensorType["CAMERA"]
<SensorType.CAMERA: 'CAMERA'>
>>> SensorType.CAMERA.name
'CAMERA'
>>> SensorType.CAMERA.value
'CAMERA'
class tensorbay.sensor.sensor.Sensor(name)[source]

Bases: tensorbay.utility.name.NameMixin, tensorbay.utility.type.TypeMixin[tensorbay.sensor.sensor.SensorType]

Sensor defines the concept of sensor.

Sensor includes name, description, translation and rotation.

Parameters

name (str) – Sensor’s name.

Raises

TypeError – Can not instantiate abstract class Sensor.

Return type

tensorbay.sensor.sensor._T

extrinsics

The translation and rotation of the sensor.

Type

tensorbay.geometry.transform.Transform3D

static loads(contents)[source]

Loads a Sensor from a dict containing the sensor information.

Parameters

contents (Dict[str, Any]) – A dict containing name, description and sensor extrinsics.

Returns

A Sensor instance containing the information from the contents dict.

Return type

_Type

Examples

>>> contents = {
...     "name": "Lidar1",
...     "type": "LIDAR",
...     "extrinsics": {
...         "translation": {"x": 1.1, "y": 2.2, "z": 3.3},
...         "rotation": {"w": 1.1, "x": 2.2, "y": 3.3, "z": 4.4},
...     },
... }
>>> sensor = Sensor.loads(contents)
>>> sensor
Lidar("Lidar1")(
    (extrinsics): Transform3D(
        (translation): Vector3D(1.1, 2.2, 3.3),
        (rotation): quaternion(1.1, 2.2, 3.3, 4.4)
    )
)
dumps()[source]

Dumps the sensor into a dict.

Returns

A dict containing the information of the sensor.

Return type

Dict[str, Any]

Examples

>>> # sensor is the object initialized from self.loads() method.
>>> sensor.dumps()
{
    'name': 'Lidar1',
    'type': 'LIDAR',
    'extrinsics': {'translation': {'x': 1.1, 'y': 2.2, 'z': 3.3},
    'rotation': {'w': 1.1, 'x': 2.2, 'y': 3.3, 'z': 4.4}
    }
}
set_extrinsics(translation=(0, 0, 0), rotation=(1, 0, 0, 0), *, matrix=None)[source]

Set the extrinsics of the sensor.

Parameters
  • translation (Iterable[float]) – Translation parameters.

  • rotation (Union[Iterable[float], quaternion.quaternion]) – Rotation in a sequence of [w, x, y, z] or numpy quaternion.

  • matrix (Optional[Union[Sequence[Sequence[float]], numpy.ndarray]]) – A 3x4 or 4x4 transform matrix.

Return type

None

Examples

>>> sensor.set_extrinsics(translation=translation, rotation=rotation)
>>> sensor
Lidar("Lidar1")(
    (extrinsics): Transform3D(
        (translation): Vector3D(1, 2, 3),
        (rotation): quaternion(1, 2, 3, 4)
    )
)
set_translation(x, y, z)[source]

Set the translation of the sensor.

Parameters
  • x (float) – The x coordinate of the translation.

  • y (float) – The y coordinate of the translation.

  • z (float) – The z coordinate of the translation.

Return type

None

Examples

>>> sensor.set_translation(x=2, y=3, z=4)
>>> sensor
Lidar("Lidar1")(
    (extrinsics): Transform3D(
        (translation): Vector3D(2, 3, 4),
        ...
    )
)
set_rotation(w=None, x=None, y=None, z=None, *, quaternion=None)[source]

Set the rotation of the sensor.

Parameters
  • w (Optional[float]) – The w componet of the roation quaternion.

  • x (Optional[float]) – The x componet of the roation quaternion.

  • y (Optional[float]) – The y componet of the roation quaternion.

  • z (Optional[float]) – The z componet of the roation quaternion.

  • quaternion (Optional[quaternion.quaternion]) – Numpy quaternion representing the rotation.

Return type

None

Examples

>>> sensor.set_rotation(2, 3, 4, 5)
>>> sensor
Lidar("Lidar1")(
    (extrinsics): Transform3D(
        ...
        (rotation): quaternion(2, 3, 4, 5)
    )
)
class tensorbay.sensor.sensor.Lidar(name)[source]

Bases: tensorbay.sensor.sensor.Sensor

Lidar defines the concept of lidar.

Lidar is a kind of sensor for measuring distances by illuminating the target with laser light and measuring the reflection.

Examples

>>> lidar = Lidar("Lidar1")
>>> lidar.set_extrinsics(translation=translation, rotation=rotation)
>>> lidar
Lidar("Lidar1")(
    (extrinsics): Transform3D(
        (translation): Vector3D(1, 2, 3),
        (rotation): quaternion(1, 2, 3, 4)
    )
)
Parameters

name (str) –

Return type

tensorbay.sensor.sensor._T

class tensorbay.sensor.sensor.Radar(name)[source]

Bases: tensorbay.sensor.sensor.Sensor

Radar defines the concept of radar.

Radar is a detection system that uses radio waves to determine the range, angle, or velocity of objects.

Examples

>>> radar = Radar("Radar1")
>>> radar.set_extrinsics(translation=translation, rotation=rotation)
>>> radar
Radar("Radar1")(
    (extrinsics): Transform3D(
        (translation): Vector3D(1, 2, 3),
        (rotation): quaternion(1, 2, 3, 4)
    )
)
Parameters

name (str) –

Return type

tensorbay.sensor.sensor._T

class tensorbay.sensor.sensor.Camera(name)[source]

Bases: tensorbay.sensor.sensor.Sensor

Camera defines the concept of camera.

Camera includes name, description, translation, rotation, cameraMatrix and distortionCoefficients.

Parameters

name (str) –

Return type

tensorbay.sensor.sensor._T

extrinsics

The translation and rotation of the camera.

Type

tensorbay.geometry.transform.Transform3D

intrinsics

The camera matrix and distortion coefficients of the camera.

Type

tensorbay.sensor.intrinsics.CameraIntrinsics

Examples

>>> from tensorbay.geometry import Vector3D
>>> from numpy import quaternion
>>> camera = Camera('Camera1')
>>> translation = Vector3D(1, 2, 3)
>>> rotation = quaternion(1, 2, 3, 4)
>>> camera.set_extrinsics(translation=translation, rotation=rotation)
>>> camera.set_camera_matrix(fx=1.1, fy=1.1, cx=1.1, cy=1.1)
>>> camera.set_distortion_coefficients(p1=1.2, p2=1.2, k1=1.2, k2=1.2)
>>> camera
Camera("Camera1")(
    (extrinsics): Transform3D(
        (translation): Vector3D(1, 2, 3),
        (rotation): quaternion(1, 2, 3, 4)
    ),
    (intrinsics): CameraIntrinsics(
        (camera_matrix): CameraMatrix(
            (fx): 1.1,
            (fy): 1.1,
            (cx): 1.1,
            (cy): 1.1,
            (skew): 0
        ),
        (distortion_coefficients): DistortionCoefficients(
            (p1): 1.2,
            (p2): 1.2,
            (k1): 1.2,
            (k2): 1.2
        )
    )
)
classmethod loads(contents)[source]

Loads a Camera from a dict containing the camera information.

Parameters

contents (Dict[str, Any]) – A dict containing name, description, extrinsics and intrinsics.

Returns

A Camera instance containing information from contents dict.

Return type

tensorbay.sensor.sensor._T

Examples

>>> contents = {
...     "name": "Camera1",
...     "type": "CAMERA",
...     "extrinsics": {
...           "translation": {"x": 1, "y": 2, "z": 3},
...           "rotation": {"w": 1.0, "x": 2.0, "y": 3.0, "z": 4.0},
...     },
...     "intrinsics": {
...         "cameraMatrix": {"fx": 1, "fy": 1, "cx": 1, "cy": 1, "skew": 0},
...         "distortionCoefficients": {"p1": 1, "p2": 1, "k1": 1, "k2": 1},
...     },
... }
>>> Camera.loads(contents)
Camera("Camera1")(
        (extrinsics): Transform3D(
            (translation): Vector3D(1, 2, 3),
            (rotation): quaternion(1, 2, 3, 4)
        ),
        (intrinsics): CameraIntrinsics(
            (camera_matrix): CameraMatrix(
                (fx): 1,
                (fy): 1,
                (cx): 1,
                (cy): 1,
                (skew): 0
            ),
            (distortion_coefficients): DistortionCoefficients(
                (p1): 1,
                (p2): 1,
                (k1): 1,
                (k2): 1
            )
        )
    )
dumps()[source]

Dumps the camera into a dict.

Returns

A dict containing name, description, extrinsics and intrinsics.

Return type

Dict[str, Any]

Examples

>>> camera.dumps()
{
    'name': 'Camera1',
    'type': 'CAMERA',
    'extrinsics': {
        'translation': {'x': 1, 'y': 2, 'z': 3},
        'rotation': {'w': 1.0, 'x': 2.0, 'y': 3.0, 'z': 4.0}
    },
    'intrinsics': {
        'cameraMatrix': {'fx': 1, 'fy': 1, 'cx': 1, 'cy': 1, 'skew': 0},
        'distortionCoefficients': {'p1': 1, 'p2': 1, 'k1': 1, 'k2': 1}
    }
}
set_camera_matrix(fx=None, fy=None, cx=None, cy=None, skew=0, *, matrix=None)[source]

Set camera matrix.

Parameters
  • fx (Optional[float]) – The x axis focal length expressed in pixels.

  • fy (Optional[float]) – The y axis focal length expressed in pixels.

  • cx (Optional[float]) – The x coordinate of the so called principal point that should be in the center of the image.

  • cy (Optional[float]) – The y coordinate of the so called principal point that should be in the center of the image.

  • skew (float) – It causes shear distortion in the projected image.

  • matrix (Optional[Union[Sequence[Sequence[float]], numpy.ndarray]]) – Camera matrix in 3x3 sequence.

Return type

None

Examples

>>> camera.set_camera_matrix(fx=1.1, fy=2.2, cx=3.3, cy=4.4)
>>> camera
Camera("Camera1")(
    ...
    (intrinsics): CameraIntrinsics(
        (camera_matrix): CameraMatrix(
            (fx): 1.1,
            (fy): 2.2,
            (cx): 3.3,
            (cy): 4.4,
            (skew): 0
        ),
        ...
        )
    )
)
set_distortion_coefficients(**kwargs)[source]

Set distortion coefficients.

Parameters
  • **kwargs – Float values to set distortion coefficients.

  • kwargs (float) –

Raises

ValueError – When intrinsics is not set yet.

Return type

None

Examples

>>> camera.set_distortion_coefficients(p1=1.1, p2=2.2, k1=3.3, k2=4.4)
>>> camera
Camera("Camera1")(
    ...
    (intrinsics): CameraIntrinsics(
        ...
        (distortion_coefficients): DistortionCoefficients(
            (p1): 1.1,
            (p2): 2.2,
            (k1): 3.3,
            (k2): 4.4
        )
    )
)
class tensorbay.sensor.sensor.FisheyeCamera(name)[source]

Bases: tensorbay.sensor.sensor.Camera

FisheyeCamera defines the concept of fisheye camera.

Fisheye camera is an ultra wide-angle lens that produces strong visual distortion intended to create a wide panoramic or hemispherical image.

Examples

>>> fisheye_camera = FisheyeCamera("FisheyeCamera1")
>>> fisheye_camera.set_extrinsics(translation=translation, rotation=rotation)
>>> fisheye_camera
FisheyeCamera("FisheyeCamera1")(
    (extrinsics): Transform3D(
        (translation): Vector3D(1, 2, 3),
        (rotation): quaternion(1, 2, 3, 4)
    )
)
Parameters

name (str) –

Return type

tensorbay.sensor.sensor._T

class tensorbay.sensor.sensor.Sensors[source]

Bases: tensorbay.utility.name.SortedNameList[Union[Radar, Lidar, FisheyeCamera, Camera]]

This class represents all sensors in a FusionSegment.

classmethod loads(contents)[source]

Loads a Sensors instance from the given contents.

Parameters

contents (List[Dict[str, Any]]) –

A list of dict containing the sensors information in a fusion segment, whose format should be like:

[
    {
        "name": <str>
        "type": <str>
        "extrinsics": {
            "translation": {
                "x": <float>
                "y": <float>
                "z": <float>
            },
            "rotation": {
                "w": <float>
                "x": <float>
                "y": <float>
                "z": <float>
            },
        },
        "intrinsics": {           --- only for cameras
            "cameraMatrix": {
                "fx": <float>
                "fy": <float>
                "cx": <float>
                "cy": <float>
                "skew": <float>
            }
            "distortionCoefficients": {
                "k1": <float>
                "k2": <float>
                "p1": <float>
                "p2": <float>
                ...
            }
        },
        "desctiption": <str>
    },
    ...
]

Returns

The loaded Sensors instance.

Return type

tensorbay.sensor.sensor._T

dumps()[source]

Return the information of all the sensors.

Returns

A list of dict containing the information of all sensors:

[
    {
        "name": <str>
        "type": <str>
        "extrinsics": {
            "translation": {
                "x": <float>
                "y": <float>
                "z": <float>
            },
            "rotation": {
                "w": <float>
                "x": <float>
                "y": <float>
                "z": <float>
            },
        },
        "intrinsics": {           --- only for cameras
            "cameraMatrix": {
                "fx": <float>
                "fy": <float>
                "cx": <float>
                "cy": <float>
                "skew": <float>
            }
            "distortionCoefficients": {
                "k1": <float>
                "k2": <float>
                "p1": <float>
                "p2": <float>
                ...
            }
        },
        "desctiption": <str>
    },
    ...
]

Return type

List[Dict[str, Any]]