设备
设备
设备 API
Device 对象代表一个 OAK 设备。启动设备时,您必须向其上传一个 Pipeline,该 Pipeline 将在 VPU 上执行。 当您在代码中创建设备时,固件会与 Pipeline 和其他资产(例如 NN 模块)一起上传。Python
1with dai.Pipeline() as pipeline:
2 device = pipeline.getDefaultDevice()
3 # Print DeviceID, USB speed, and available cameras on the device
4 print('DeviceID:',device.getDeviceInfo().getDeviceId())
5 print('USB speed:',device.getUsbSpeed())
6 print('Connected cameras:',device.getConnectedCameras())连接到指定设备
Python
1# Specify DeviceID, IP Address or USB path
2device_info = depthai.DeviceInfo("14442C108144F1D000") # DeviceID
3#device_info = depthai.DeviceInfo("192.168.1.44") # IP Address
4#device_info = depthai.DeviceInfo("3.3.3") # USB port name
5with depthai.Device(device_info) as device:
6 # ...时钟
dai.Clock.now() (Python) 或 dai::Clock::now() (C++) 是一个单调时钟,用于 depthai 库中的时间戳。它源自 std::chrono::steady_clock,不受系统时间更改(例如 NTP 同步)的影响。该方法返回自主机(PC)启动以来的 datetime.timedelta (Python) 或 std::chrono::steady_clock::duration (C++)。它用于在设备 消息 上调用 getTimestamp(),并指示消息在设备上创建的时 间。设备上还有一个单独的单调时钟,用于检索自设备(OAK)启动以来的时间,可以通过 getTimestampDevice() 调用。主机时钟同步



Python
1# 配置主机时钟同步示例
2
3import depthai as dai
4from datetime import timedelta
5# 配置 Pipeline
6with dai.Pipeline() as pipeline:
7 device = pipeline.getDefaultDevice()
8 # 第一个值:timesync 运行之间的间隔
9 # 第二个值:每次运行用于计算更好值的 timesync 样本数
10 # 第三个值:如果为 true,则将在随机间隔执行部分 timesync 请求,否则将在固定间隔执行
11 device.setTimesync(timedelta(seconds=5), 10, True) # (这些是默认值)看门狗 - 仅限 RVC2
自定义看门狗超时
DEPTHAI_WATCHDOG_INITIAL_DELAY 和 DEPTHAI_BOOTUP_TIMEOUT 设置为您想要的超时值(以毫秒为单位),如下所示:Linux/macOS
Command Line
1DEPTHAI_WATCHDOG_INITIAL_DELAY=<my_value> DEPTHAI_BOOTUP_TIMEOUT=<my_value> python3 script.pyPython
1pipeline = depthai.Pipeline()
2
3# 创建一个 BoardConfig 对象
4config = depthai.BoardConfig()
5
6# 设置参数
7config.watchdogInitialDelayMs = <my_value>
8config.watchdogTimeoutMs = <my_value>
9
10pipeline.setBoardConfig(config)环境变量
| 环境变量 | 描述 |
|---|---|
DEPTHAI_LEVEL | 设置日志详细程度,选项:'trace', 'debug', 'info', 'warn', 'error', 'off' |
XLINK_LEVEL | 设置 XLink 库的日志详细程度,选项:'debug', 'info', 'warn', 'error', 'fatal', 'off' |
DEPTHAI_INSTALL_SIGNAL_HANDLER | 设置为 0 以禁用安装后向信号处理程序以打印堆栈跟踪 |
DEPTHAI_WATCHDOG | 设置设备看门狗超时。用于调试(DEPTHAI_WATCHDOG=0),以防止在进程暂停时重置设备。 |
DEPTHAI_WATCHDOG_INITIAL_DELAY | 指定设备看门狗启动后的延迟。 |
DEPTHAI_SEARCH_TIMEOUT | 指定阻塞函数中设备搜索的超时时间(以毫秒为单位)。 |
DEPTHAI_CONNECT_TIMEOUT | 指定与给定设备建立连接的超时时间(以毫秒为单位)。 |
DEPTHAI_BOOTUP_TIMEOUT | 指定发送二进制文件后等待设备启动的超时时间(以毫秒为单位)。 |
DEPTHAI_RECONNECT_TIMEOUT | 指定连接丢失后重新连接设备的超时时间(以毫秒为单位)。如果设置为 0,则禁用重新连接。 |
DEPTHAI_PROTOCOL | 将默认搜索限制为指定的协议。选项:any, usb, tcpip, tcpshd。 |
DEPTHAI_PLATFORM | 将默认搜索限制为指定的平台。选项:any, rvc2, rvc3, rvc4。 |
DEPTHAI_DEVICE_MXID_LIST | 将默认搜索限制为指定的 MXID。接受逗号分隔的 MXID 列表。列表以“AND”方式过滤结果,而不是“OR”。 |
DEPTHAI_DEVICE_ID_LIST | MXID 列表的别名。列表以“AND”方式过滤结果,而不是“OR”。 |
DEPTHAI_DEVICE_NAME_LIST | 将默认搜索限制为指定的名称。接受逗号分隔的名称列表。列表以“AND”方式过滤结果,而不是“OR”。对于 tcpip,它还会查找主机子网之外的名称。 |
DEPTHAI_DEVICE_BINARY | 覆盖设备固件二进制文件。主要用于内部调试目的。 |
DEPTHAI_DEVICE_RVC4_FWP | 覆盖设备 RVC4 固件二进制文件。主要用于内部调试目的。 |
DEPTHAI_BOOTLOADER_BINARY_USB | 覆盖设备 USB 引导加载程序二进制文件。主要用于内部调试目的。 |
DEPTHAI_BOOTLOADER_BINARY_ETH | 覆盖设备网络引导加载程序二进制文件。主要用于内部调试目的。 |
DEPTHAI_ALLOW_FACTORY_FLASHING | 仅供内部使用 |
DEPTHAI_LIBUSB_ANDROID_JAVAVM | 传递给 libusb 的 JavaVM 指针,用于无根 Android 与设备的交互。解释为 uintptr_t 的十进制值。 |
DEPTHAI_CRASHDUMP | 保存崩溃转储的目录。 |
DEPTHAI_CRASHDUMP_TIMEOUT | 指定获取崩溃转储时等待设备重启的持续时间(以毫秒为单位)。如果为 0,则禁用崩溃转储检索。 |
DEPTHAI_ENABLE_ANALYTICS_COLLECTION | 启用自动分析收集(管道模式),用于改进库。 |
DEPTHAI_DISABLE_CRASHDUMP_COLLECTION | 禁用用于改进库的自动崩溃转储收集。 |
DEPTHAI_HUB_EVENTS_BASE_URL | Luxonis Hub 事件的 URL |
DEPTHAI_HUB_API_KEY | Luxonis Hub 的 API 密钥 |
DEPTHAI_ZOO_INTERNET_CHECK | (默认) 1 - 执行互联网检查,如果可用,下载最新的模型版本;0 - 跳过互联网检查并使用缓存的模型 |
DEPTHAI_ZOO_INTERNET_CHECK_TIMEOUT | (默认) 1000 - 互联网检查的超时时间(以毫秒为单位) |
DEPTHAI_ZOO_CACHE_PATH | (默认) .depthai_cached_models - 缓存的 zoo 模型存储文件夹 |
DEPTHAI_ZOO_MODELS_PATH | (默认) depthai_models - zoo 模型描述文件存储文件夹 |
DEPTHAI_RECORD | 启用到指定目录的整体记录。 |
DEPTHAI_REPLAY | 从指定文件或目录重放整体回放。 |
DEPTHAI_PROFILING | 启用主机和连接设备之间数据传输的运行时分析。设置为 1 以启用。需要 DEPTHAI_LEVEL=debug 或更低级别才能打印。 |
参考
class
dai::Device
function
Device()Connects to any available device with a DEFAULT_SEARCH_TIME timeout. Uses OpenVINO version OpenVINO::VERSION_UNIVERSAL
function
~Device()function
DeviceBase()Connects to any available device with a DEFAULT_SEARCH_TIME timeout. Uses OpenVINO version OpenVINO::VERSION_UNIVERSAL
function
DeviceBase(UsbSpeed maxUsbSpeed)Connects to device
Parameters
- maxUsbSpeed: Maximum allowed USB speed
function
DeviceBase(const DeviceInfo & devInfo, UsbSpeed maxUsbSpeed)Connects to device specified by devInfo.
Parameters
- devInfo: DeviceInfo which specifies which device to connect to
- maxUsbSpeed: Maximum allowed USB speed
function
DeviceBase(const DeviceInfo & devInfo, const std::filesystem::path & pathToCmd)Connects to device specified by devInfo.
Parameters
- devInfo: DeviceInfo which specifies which device to connect to
- pathToCmd: Path to custom device firmware
explicit function
DeviceBase(Config config)Connects to any available device with custom config.
Parameters
- config: Device custom configuration to boot with
function
DeviceBase(Config config, const DeviceInfo & devInfo)Connects to device 'devInfo' with custom config.
Parameters
- config: Device custom configuration to boot with
- devInfo: DeviceInfo which specifies which device to connect to
explicit function
DeviceBase(const DeviceInfo & devInfo)Connects to any available device with a DEFAULT_SEARCH_TIME timeout. Uses OpenVINO version OpenVINO::VERSION_UNIVERSAL
Parameters
- devInfo: DeviceInfo which specifies which device to connect to
function
DeviceBase(std::string nameOrDeviceId)Connects to any available device with a DEFAULT_SEARCH_TIME timeout. Uses OpenVINO version OpenVINO::VERSION_UNIVERSAL
Parameters
- nameOrDeviceId: Creates DeviceInfo with nameOrDeviceId to connect to
function
DeviceBase(std::string nameOrDeviceId, UsbSpeed maxUsbSpeed)Connects to any available device with a DEFAULT_SEARCH_TIME timeout. Uses OpenVINO version OpenVINO::VERSION_UNIVERSAL
Parameters
- nameOrDeviceId: Creates DeviceInfo with nameOrDeviceId to connect to
- maxUsbSpeed: Maximum allowed USB speed
function
DeviceBase(Config config, UsbSpeed maxUsbSpeed)Connects to device specified by devInfo.
Parameters
- config: Config with which the device will be booted with
- maxUsbSpeed: Maximum allowed USB speed
function
DeviceBase(Config config, const std::filesystem::path & pathToCmd)Connects to any available device with a DEFAULT_SEARCH_TIME timeout.
Parameters
- config: Config with which the device will be booted with
- pathToCmd: Path to custom device firmware
function
DeviceBase(Config config, const DeviceInfo & devInfo, UsbSpeed maxUsbSpeed)Connects to device specified by devInfo.
Parameters
- config: Config with which the device will be booted with
- devInfo: DeviceInfo which specifies which device to connect to
- maxUsbSpeed: Maximum allowed USB speed
function
DeviceBase(Config config, const DeviceInfo & devInfo, const std::filesystem::path & pathToCmd, bool dumpOnly)Connects to device specified by devInfo.
Parameters
- config: Config with which the device will be booted with
- devInfo: DeviceInfo which specifies which device to connect to
- pathToCmd: Path to custom device firmware
- dumpOnly: If true only the minimal connection is established to retrieve the crash dump
enum