Skip to content

senxor.utils

senxor.utils

Utilities for Senxor devices.

connect(address=None, type=None, *, auto_open=True, stop_stream=True, **kwargs)

Connect to a Senxor device.

Parameters:

Name Type Description Default
address str | ListPortInfo

The address of the device to connect to.

None
type Literal['serial']

The type of device to connect to. If not provided, will attempt to auto-detect from address.

None
auto_open bool

Whether to automatically open the device.

True
stop_stream bool

Whether to stop the stream when the device is opened.

True
**kwargs

Additional arguments passed to the interface constructor.

{}

Returns:

Type Description
Senxor

The Senxor device.

Examples:

Use a context manager to connect to a device:

>>> from senxor import list_senxor, connect
>>> addrs = list_senxor("serial")
>>> with connect(addrs[0]) as dev:
...     print(f"Connected to device {dev.address}")
Connected to device COM3

Or connect to a device without a context manager:

>>> dev = connect(addrs[0])
>>> print(f"Connected to device {dev.address}")
Connected to device COM3

It's recommended to use a context manager because it will automatically close the device when the context is exited.

data_to_frame(data, array_shape=None, *, hflip=False)

Convert raw data to a frame.

It's used for backward compatibility.

Parameters:

Name Type Description Default
data ndarray

The raw data.

required
array_shape tuple[int, int] | None

Not needed, it's for backward compatibility.

None
hflip bool

Whether to flip the image horizontally.

False

Returns:

Type Description
ndarray

The frame.

is_senxor_usb(port)

Check if the port is a senxor port.

Parameters:

Name Type Description Default
port ListPortInfo | str

The port to check. Use list_ports.comports() to get the list of ports.

required

Returns:

Type Description
bool

True if the port is a senxor port, False otherwise.

Examples:

>>> ports = list_ports.comports()
>>> for port in ports:
>>>     if is_senxor_port(port):
>>>         print(port.device)

list_camera()

List all cameras available.

Warning:

This function is deprecated. Use list_camera_info instead.

Returns:

list[str] A list of camera names.

Examples:

list_camera() ['Camera 0', 'Camera 1', 'Camera 2']

You can use cv2.VideoCapture(index) to open a camera.

list_senxor(type=None, exclude=None)

List all Senxor devices available.

The return value is a list of Senxor devices, use senxor.connect to connect to a device.

Parameters:

Name Type Description Default
type Literal['serial'] | None

The type of device to list. If not provided, all types will be listed.

None
exclude list[str] | str | None

If type is provided, this will be ignored. A list of device names to exclude from the list. If not provided, all devices will be listed.

None

Returns:

Type Description
list

A list of Senxor devices, use senxor.connect to connect to a device.

list_senxor_usb(exclude_open_ports=True)

List all the senxor ports.

Parameters:

Name Type Description Default
exclude_open_ports bool

If True, exclude the ports that are currently open (in use). If False, include the ports that are currently open (in use). Default is True.

True

Returns:

Type Description
list[ListPortInfo]

The list of senxor ports.

Examples:

>>> ports = list_senxor_ports()
>>> print([port.device for port in ports])
['COM5', 'COM6']

remap(image, in_range=None, out_range=None, dtype=np.uint8)

Remap image intensity to a desired range and data type using NumPy.

It's equivalent to normalize(..., dtype=np.uint8).

Parameters:

Name Type Description Default
image ndarray

The image to remap.

required
in_range tuple | None

The input range of the image. If None, the image's min/max are used.

None
out_range tuple | None

The output range of the image.

None
dtype Any

The data type of the image.

uint8

Returns:

Type Description
ndarray

The remapped image.