create Method
- Sensor.create(cam_id=0, use_gpu=True, config_path=None, api=None, check_serial=True, rectify_size=None, ip_address=None, video_path=None)
Create a sensor instance; after use, call
release()to release resources.- Parameters:
cam_id (int | str, 可选) – Sensor ID, serial number, or video path. Defaults to 0.
use_gpu (bool, 可选) – Whether to use GPU for inference.
config_path (str | Path, 可选) – Configuration file path or directory. If it is a directory, it must contain a calibration file with the same name as the sensor serial number.
api (Enum, 可选) – Camera API type (e.g., OpenCV backend), used to specify the camera access method.
check_serial (bool, 可选) – Whether to check the sensor serial number.
rectify_size (tuple[int, int], 可选) – Corrected image size (width, height).
mac_address (str, 可选) – Camera MAC address used for remote connection.
video_path (str, 可选) – Video path for offline simulation.
- Returns:
A sensor instance for subsequent data collection and processing.
- Return type:
Sensor
Note
Be sure to call release() to release system resources after use.
Example Code
from xensesdk import Sensor
# 使用传感器序列号(SN)创建实例
sensor = Sensor.create('OP000064')
# 使用完毕后释放资源
sensor.release()
from xensesdk import Sensor
# 使用相机编号(如 0、1)创建实例
sensor = Sensor.create(0)
# 使用完毕后释放资源
sensor.release()
from xensesdk import Sensor
# 通过 video_path 加载本地数据(cam_id 设为 None)
sensor = Sensor.create(None, video_path=r"data.h5")
# 使用完毕后释放资源
sensor.release()
from xensesdk import Sensor
# 指定 IP 地址连接远程传感器
sensor = Sensor.create('OP000064', ip_address="192.168.66.66")
# 使用完毕后释放资源
sensor.release()
Tips
The mac_address parameter in Example 4 is compatible with the device IP address. For how to obtain the device MAC, refer to EzROS.