快速开始
下面的程序通过序列号连接传感器,并在同一次采集中获取校正图和深度图:
from time import sleep
from xensesdk import Sensor
def main():
# 也可以传入相机编号 0/1,或远程连接时传入 mac_addr
sensor = Sensor.create("OP000064")
try:
while True:
rectify, depth = sensor.selectSensorInfo(
Sensor.OutputType.Rectify,
Sensor.OutputType.Depth,
)
if rectify is not None:
print("rectify:", rectify.shape, rectify.dtype)
if depth is not None:
print("depth:", depth.shape, depth.dtype)
sleep(0.02)
except KeyboardInterrupt:
print("采集已停止")
finally:
sensor.release()
if __name__ == "__main__":
main()
选择连接方式
Sensor.create(0) # 本地相机编号
Sensor.create("OP000064") # 传感器序列号
Sensor.create("OP000064", mac_addr="...") # 算力板上的远程传感器
Sensor.create("OP000064", infer_mode="small") # 指定推理模式
Sensor.create(0, disable_infer=True) # 只验证采集链路
不要在多个线程中重复创建同一个传感器。长时间运行时,请在 finally 中释放实例,避免摄像头句柄和推理线程泄漏。
更多代码示例查看本地连接、远程连接、输出类型和数据处理示例。
打开 GitHub 示例 ↗如果现有示例未覆盖你的使用场景,可以在项目的 Issues 中说明需求。