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: str)[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

nameSensor’s name.

Raises

TypeError – Can not instantiate abstract class Sensor.

extrinsics

The translation and rotation of the sensor.

Type

tensorbay.geometry.transform.Transform3D

static loads(contents: Dict[str, Any]) _Type[source]

Loads a Sensor from a dict containing the sensor information.

Parameters

contents – A dict containing name, description and sensor extrinsics.

Returns

A Sensor instance containing the information from the contents dict.

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() Dict[str, Any][source]

Dumps the sensor into a dict.

Returns

A dict containing the information of the sensor.

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: Iterable[float] = (0, 0, 0), rotation: Union[Iterable[float], quaternion.quaternion] = (1, 0, 0, 0), *, matrix: Optional[Union[Sequence[Sequence[float]], numpy.ndarray]] = None) None[source]

Set the extrinsics of the sensor.

Parameters
  • translation – Translation parameters.

  • rotation – Rotation in a sequence of [w, x, y, z] or numpy quaternion.

  • matrix – A 3x4 or 4x4 transform matrix.

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: float, y: float, z: float) None[source]

Set the translation of the sensor.

Parameters
  • x – The x coordinate of the translation.

  • y – The y coordinate of the translation.

  • z – The z coordinate of the translation.

Examples

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

Set the rotation of the sensor.

Parameters
  • w – The w componet of the roation quaternion.

  • x – The x componet of the roation quaternion.

  • y – The y componet of the roation quaternion.

  • z – The z componet of the roation quaternion.

  • quaternion – Numpy quaternion representing the rotation.

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: str)[source]

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

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)
    )
)
class tensorbay.sensor.sensor.Radar(name: str)[source]

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

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)
    )
)
class tensorbay.sensor.sensor.Camera(name: str)[source]

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

Camera defines the concept of camera.

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

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: Dict[str, Any]) tensorbay.sensor.sensor._T[source]

Loads a Camera from a dict containing the camera information.

Parameters

contents – A dict containing name, description, extrinsics and intrinsics.

Returns

A Camera instance containing information from contents dict.

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() Dict[str, Any][source]

Dumps the camera into a dict.

Returns

A dict containing name, description, extrinsics and intrinsics.

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: Optional[float] = None, fy: Optional[float] = None, cx: Optional[float] = None, cy: Optional[float] = None, skew: float = 0, *, matrix: Optional[Union[Sequence[Sequence[float]], numpy.ndarray]] = None) None[source]

Set camera matrix.

Parameters
  • fx – The x axis focal length expressed in pixels.

  • fy – The y axis focal length expressed in pixels.

  • cx – The x coordinate of the so called principal point that should be in the center of the image.

  • cy – The y coordinate of the so called principal point that should be in the center of the image.

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

  • matrix – Camera matrix in 3x3 sequence.

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: float) None[source]

Set distortion coefficients.

Parameters

**kwargs – Float values to set distortion coefficients.

Raises

ValueError – When intrinsics is not set yet.

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: str)[source]

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

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)
    )
)
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: List[Dict[str, Any]]) tensorbay.sensor.sensor._T[source]

Loads a Sensors instance from the given contents.

Parameters

contents

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.

dumps() List[Dict[str, Any]][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>
    },
    ...
]