Developer Interface

Camera Module

class TauLidarCamera.camera.Camera

ToF camera class, access point to the ToF camera.

TauLidarCamera library depends on the TauLidarCommon library.

If you install TauLidarCamera using pip (pip install TauLidarCamera), TauLidarCommon library will be automaticall installed.

To initiate an instance of Camera object, call static method of Camera.open(port=None).

close()

Close communication to the camera.

static composeFrame(dataArray, frameType)

Convenient method to compose Frame using raw bytearray data.

To compose a Frame object, you need to specify which FrameType of the raw data, which may be:

FrameType.DISTANCE: distance / depth only

FrameType.DISTANCE_GRAYSCALE: distance / depth plus grayscale

FrameType.DISTANCE_AMPLITUDE: distance / depth plus amplitude

Returns:

An instance of Frame.

The members of the Frame object will be populated:

data_depth, data_depth_rgb, points_3d

In addition, depends on the FrameType requested, additional member may be populated:

FrameType.DISTANCE_GRAYSCALE: data_grayscale.

FrameType.DISTANCE_AMPLITUDE: data_amplitude.

Return type:

Frame

getChipInformation()

request Chip Information.

getFirmwareRelease()

request Firmware Release.

getIdentification()

request Identification.

info()

get camera information, such as model, firmware version, uid, resolution and serial port name.

Returns:

An instance of CameraInfo contains model, firmware version, uid, resolution and serial port name.

Return type:

CameraInfo

static open(port=None)

open communication to the camera via serial port.

By default, Camera will connect to the first available ToF device. Alternatively can specify serial port ‘/dev/ttyACM0’:

Camera.open(‘/dev/ttyACM0’)

Parameters:

port (str, optional) – serial port the camera connected. if there is no port given, the first available camera will be used.

Returns:

An instance of Camera object which connected to the ToF camera.

Return type:

Camera

Raises:

Exception – Error to open the camera.

readFrame(frameType=TauLidarCommon.frame.FrameType.DISTANCE_GRAYSCALE)

A convenient method to directly get a new Frame object.

Specifying a frameType to get a frame with distance / depth only, or distance / depth plus grayscale or amplitude:

FrameType.DISTANCE: distance / depth only

FrameType.DISTANCE_GRAYSCALE: distance / depth plus grayscale

FrameType.DISTANCE_AMPLITUDE: distance / depth plus amplitude

This method is an expensive call, alternatively you may use readFrameRawData and compose Frame from a separate thread in your application to get better frame rate.

For example, for an application which the frame rate is not critical, a simple call of readFrame to get an instance of Frame object:

frame = camera.readFrame(self, frameType=FrameType.DISTANCE)

If your application require a fast frame rate, it might be a good idea to request frame raw data and compose Frame object in different threads:

The local thread to request a frame raw data:

dataArray = self.readFrameRawData(frameType)

In another thread to compose the Frame object from dataArray, and the local thread can continue to request next frame raw data:

_frameBuilder.composeFrame(dataArray, frameType)

Returns:

  • Frame – An instance of Frame.

  • The members of the Frame object will be populated – data_depth,

    data_depth_rgb, points_3d

    In addition, depends on the FrameType requested, additional member may be populated:

    FrameType.DISTANCE_GRAYSCALE: data_grayscale.

    FrameType.DISTANCE_AMPLITUDE: data_amplitude.

  • Example of converting data_depth_rgb to OpenCV Mat object – mat_depth_rgb = np.frombuffer(frame.data_depth_rgb, dtype=np.uint16, count=-1, offset=0).reshape(frame.height, frame.width, 3) mat_depth_rgb = mat_depth_rgb.astype(np.uint8)

  • Example of converting data_grayscale to OpenCV Mat object – mat_grayscale = np.frombuffer(frame.data_grayscale, dtype=np.uint16, count=-1, offset=0).reshape(frame.height, frame.width) mat_grayscale = mat_grayscale.astype(np.uint8)

  • Example of converting data_amplitude to OpenCV Mat object – mat_amplitude = np.frombuffer(frame.data_amplitude, dtype=np.float32, count=-1, offset=0).reshape(frame.height, frame.width) mat_amplitude = mat_amplitude.astype(np.uint8)

readFrameRawData(frameType)

To request raw data of a frame from camera.

You may use readFrameRawData(frameType) only when you consider a two-step read-and-compose a Frame object, which readFrameRawData(frameType) to obtain a frame raw data, and then use FrameBuilder.composeFrame(dataArray, frameType) to create an Frame object, normally in a separate thread, to have a better frame rate.

You may simply call readFrame(frameType) to obtain a Frame object without using this method if the frame rate is not critical.

FrameType.DISTANCE: depth data only

FrameType.DISTANCE_GRAYSCALE: depth data plus grayscale

FrameType.DISTANCE_AMPLITUDE: depth data plus amplitude

Returns:

  • bytearray – Length of the raw data will be different depends on the frameType specified:

  • FrameType.DISTANCE (2 bytes 32 float distance for each data point, 160 (image width) x 160 (image height) x 2;)

  • FrameType.DISTANCE_GRAYSCALE (2 bytes 32 float distance and 1 byte unit 8 grayscale for each data point, 160 (image width) x 160 (image height) x (2 + 1);)

  • FrameType.DISTANCE_AMPLITUDE (2 bytes 32 float distance and 2 bytes 32 float amplitude for each data point, 160 (image width) x 160 (image height) x (2 + 2);)

static scan()

scan for available Tau LiDAR cameras

Parameters:

None

Returns:

A list of serial port device name that represents Tau cameras

Return type:

ports

static setColorMode(colorMode)

Set ColorMode. To use distance or grayscle for point cloud color.

setDefaultParameters()

Convenient method to set default parameters to control the ToF camera. You may set those parameters in your own application.

setHdr(hdr)

Set HDR mode. Currently not supported.

setIntegrationTime3d(index, t)

Set Integration Time. Integration Time could be from 0 to 1000, depends on the surface reflectivity and distance of the target object, for an object in about 2-3 meters, you may try set it to 800.

setIntegrationTimeGrayscale(t)

Set Integration Time for Grayscale. If you request distance/depth plus grayscale image, you need set approriate “integration time grayscale”, maximum allowed 25000, for example, regular in-door environment, set it to 8000.

setMinimalAmplitude(index, t)

Set MinimalAmplitude. MinimalAmplitude is the noise level minimum threshold, for an object in about 2-3 meters in in-door environment, you may try set it to 60.

setMode(mode)

Set camera mode. Currently supports wide view iamge only, which is 0.

setModulationChannel(channel)

Set Modulation Channel, for multiple cameras, you may set them work in different channels, however if you have only one, set it to 0.

setModulationFrequency(frequency)

Set Modulation Frequency, for wide view image, it has to be set to VALUE_20MHZ.

setOffset(offset)

Set distance offset. Normally this set it to 0.

static setRange(z1, z2)

Set Range. To use distance for point cloud color, set the distance range.

setRoi(x0, y0, x1, y1)

Set ROI. Currently not supported.

Communication Module

class TauLidarCamera.communication.Communication

Communication to the ToF sensor via serial port.

close()

close communication to the sensor.

getChipInformation()

get Chip Information.

getDistance()

get Distance only.

getDistanceAmplitude()

get Distance Amplitude image.

getDistanceGrayscale()

get Distance Grayscale image.

getFirmwareRelease()

get Firmware Release.

getIdentification()

get getIdentification.

open(port)

auto detect sensor at serial port and open communication to the sensor if port is not given, or open communication to specific serial port.

Parameters:

port (str) – serial port the sensor connected.

setHdr(hdr)

set HDR.

Parameters:

hdr – 0 - HDR Off

setIntegrationTime3d(index, integrationTime)

set set Integration Time 3d.

Parameters:
  • index – integrationTime index

  • integrationTime – integrationTime

setIntegrationTimeGrayscale(integrationTime)

set Integration Time Grayscale.

Parameters:

integrationTime – 0 - 50000

setMinimalAmplitude(index, amplitude)

set Minimal Amplitude.

Parameters:
  • index – MinimalAmplitude index

  • amplitude – amplitude

setMode(mode)

set Mode.

Parameters:

mode – 0 - wide FOV

setModulationChannel(autoChannelEnabled, channel)

set Modulation Channel.

Parameters:
  • autoChannelEnabled – on or off the auto Channel

  • channel – 0 - 10.

setModulationFrequency(frequency)

set Modulation Frequency.

Parameters:

frequency – VALUE_10MHZ (10mHz) or VALUE_20MHZ (20mHz).

setOffset(offset)

set Offset.

Parameters:

offset – distance offset

setRoi(xMin, yMin, xMax, yMax)

set Roi.

Parameters:
  • xMin – xMin

  • yMin – yMin

  • xMax – xMax

  • yMax – yMax

CRC Module

TauLidarCamera.crc.calculateChecksum(data, size)

Calculate Checksum.

Parameters:
  • data (bytearray) – bytearray data.

  • size (int) – size.

TauLidarCamera.crc.checksumIsCorrect(array, expectedSize)

Verify if the checksum is correct.

Parameters:
  • array (bytearray) – bytearray data.

  • expectedSize (int) – expected size.

Info Module

class TauLidarCamera.info.CameraInfo(_model, _firmware, _uid, _resolution, _port)

Camera Information.

model

Camera model.

firmware

Firmware version.

uid

Camera identification.

resolution

Camera resolution

port

Serial port

Util Module

TauLidarCamera.util.getUint16LittleEndian(array, index)

get Uint16 Little Endian.

Parameters:
  • array (bytearray) – data array.

  • index (int) – starting index.

TauLidarCamera.util.getUint32LittleEndian(array, index)

get Uint32 Little Endian.

Parameters:
  • array (bytearray) – data array.

  • index (int) – starting index.

TauLidarCamera.util.getValueLsb(value)

get Lsb value.

Parameters:

value (int) – masked value.

TauLidarCamera.util.getValueMsb(value)

get Msb value.

Parameters:

value (int) – masked value.

TauLidarCamera.util.setInt16LittleEndian(buffer, index, value)

set Int16 Little Endian.

Parameters:
  • buffer (bytearray) – data array.

  • index (int) – starting index.

  • value (int) – value to be set.

TauLidarCamera.util.setUint16LittleEndian(buffer, index, value)

set Uint16 Little Endian.

Parameters:
  • buffer (bytearray) – data array.

  • index (int) – starting index.

  • value (int) – value to be set.

TauLidarCamera.util.setUint32LittleEndian(buffer, index, value)

set Uint32 Little Endian.

Parameters:
  • buffer (bytearray) – data array.

  • index (int) – starting index.

  • value (int) – value to be set.

TauLidarCommon Library

TauLidarCamera depends on the TauLidarCommon library and makes use of the Color and Frame modules implemented in TauLidarCommon.

See the documentation for TauLidarCommon for more details.