Skip to main content

Local Mode

Local mode is used when a sensor is connected directly to the development computer. Image acquisition, data processing, and inference all run on the computer. Create a Sensor instance using either a local camera index or a sensor serial number.

Prerequisites​

  • Connect the sensor to the development computer and verify that the operating system detects it.
  • Install xensesdk[full] when local inference and built-in visualization are required.
  • To verify only the acquisition path without inference, pass disable_infer=True when creating the sensor.
  • Before using GPU inference, make sure the NVIDIA driver, CUDA Toolkit, and cuDNN are installed correctly.

Find sensors​

Use Sensor.scanSerialNumber() to list available sensors and their local camera indexes:

from xensesdk import Sensor

serial_map = Sensor.scanSerialNumber()
print(serial_map)

The result maps sensor serial numbers to camera indexes. If the result is empty, check sensor power, connectivity, device permissions, and configuration files.

Create a local sensor​

Connect by camera index:

sensor = Sensor.create(cam_id=0)

You can also connect by serial number so that reconnecting devices does not change which sensor is selected:

sensor = Sensor.create("OP000064")

Read data​

The following example reads the rectified image and depth map from the same frame:

from time import sleep
from xensesdk import Sensor

sensor = Sensor.create(cam_id=0)
try:
while True:
rectify, depth = sensor.selectSensorInfo(
Sensor.OutputType.Rectify,
Sensor.OutputType.Depth,
)
print("rectify:", rectify.shape, "depth:", depth.shape)
sleep(0.02)
except KeyboardInterrupt:
pass
finally:
sensor.release()

Requesting multiple outputs in one selectSensorInfo() call ensures that they come from the same frame. Always call sensor.release() when the program exits to release camera and inference resources. Do not create multiple instances of the same sensor from different threads.

Complete local-mode exampleSee complete code for local sensor connection, multimodal output retrieval, force plots, and visualization.
Open GitHub example ↗