DepthAI library for interfacing with Luxonis DepthAI hardware. It's written in C++ and offers Python bindings out of the box.
Important — You’re viewing the
v3.x.ybranch.
- For production projects that still rely on v2, check out the
v2_stablebranch.- Need to migrate? Follow the step-by-step v2 → v3 Porting Guide.
Documentation is available over at Luxonis DepthAI API
Examples for both C++ and Python are available in the examples folder. To see how to build and run them see README.md for more information.
To build the examples in C++ configure with the following option added:
cmake -S. -Bbuild -D'DEPTHAI_BUILD_EXAMPLES=ON'
cmake --build build
For the complete model-description YAML format, see nn_model_description.yaml.
The beta namespace is a staging area for experimental DepthAI features. It
allows new features to be developed and iterated on quickly before they are
promoted to the main depthai namespace.
The API and behavior of beta features can change between releases without notice.
In C++, beta nodes are available under dai::beta::node:
auto node = pipeline.create<dai::beta::node::ClassificationParser>();In Python, they are available under dai.beta.node:
node = pipeline.create(dai.beta.node.ClassificationParser)On-device execution of Beta nodes is supported only on RVC4. If running Beta nodes on RVC2, DepthAI automatically configures beta nodes to run on the host.
Add multiple devices to a single pipeline by calling addDevice(...). The first device
that you add becomes the master (default device): nodes created without an explicit
device run on it. For more information, see the multi-device documentation. A code example can be found at multi_device_frame_sync.py.
pipeline = dai.Pipeline(False) # no implicit device
devA = pipeline.addDevice("10.0.0.10") # promoted to master
devB = pipeline.addDevice("10.0.0.11")
camA = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A) # master
camB = pipeline.create(dai.node.Camera, device=devB).build(dai.CameraBoardSocket.CAM_A)
sync = pipeline.create(dai.node.Sync) # host Sync aligns both streams
sync.setRunOnHost(True)
camA.requestOutput((640, 400)).link(sync.inputs["a"])
camB.requestOutput((640, 400)).link(sync.inputs["b"])The pipeline process may itself run on an RVC4 and use the local device over shared memory, with further devices attached over the network:
local = pipeline.addDevice(dai.DeviceInfo.local()) # this RVC4, no search timeout
remote = pipeline.addDevice("10.0.0.11") # a remote device over TCPRequirements: outbound TCP to each remote device's gate (port 11492) and XLink ports,
and /tmp shared with the device runtime for the local socket. Note that
DEPTHAI_PROTOCOL and DEPTHAI_DEVICE_ID_LIST are process-wide discovery filters -
leave them unset (any) when mixing local and remote devices.
- CMake >= 3.20
- C/C++17 compiler
- [Linux] libudev >= 1.0.0
- Docker engine on an x86-64 host with bash, to build the RVC4 firmware (see Building the FW to skip it)
- [optional] OpenCV 4 (required if building examples and for record and replay)
- [optional] PCL (required for point cloud example)
To install them:
- libudev (Debian, Ubuntu):
sudo apt install libudev-dev - OpenCV:
brew install opencv(macOS),sudo apt install libopencv-dev(Linux),choco install opencv(Windows) - PCL:
brew install pcl(macOS),sudo apt install libpcl-dev(Linux)
Install the latest release from PyPI:
python3 -m pip install depthai
Install the latest pre-release:
python3 -m pip install --extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-release-local/ --pre -U depthai
To install the wheel of the checked-out commit and the requirements of the examples, run
python3 examples/python/install_requirements.py.
For more information, see the Python README.
Make sure submodules are updated
git submodule update --init --recursive
Then configure and build
cmake -S . -B build
cmake --build build --parallel [num CPU cores]
To build a dynamic library, add -D'BUILD_SHARED_LIBS=ON' to the configure command.
The RVC4 firmware is in device/rvc4. Each build of the library builds it automatically from that folder and embeds it, so the firmware always matches the host library of the same commit.
-
The firmware compiles in the public build container
ghcr.io/luxonis/depthai-device-sdk. -
The firmware links a prebuilt vendor module. Read its End User License Agreement first (device/rvc4), then accept it and the license terms of the Qualcomm AI Runtime SDK:
cmake -S . -B build -D DEPTHAI_ACCEPT_VENDOR_EULA=yes -D DEPTHAI_ACCEPT_QUALCOMM_LICENSE=yes cmake --build build --parallel [num CPU cores] -
To skip the firmware build, download a published package with
-D DEPTHAI_DEVICE_RVC4_VERSION=<version>, use your own with-D DEPTHAI_DEVICE_RVC4_FWP_PATH=<path>/depthai-device-rvc4-fwp.tar.xz, or build without the RVC4 firmware with-D DEPTHAI_ENABLE_DEVICE_RVC4_FW=OFF. -
To run another firmware package without a new build, set
DEPTHAI_DEVICE_RVC4_FWP=<path>(see Environment variables).
Installation of the DepthAI library is currently only available as a dynamic library. To install the library, use the following command:
cmake -S . -B build -D'BUILD_SHARED_LIBS=ON' -D'CMAKE_INSTALL_PREFIX=[path/to/install/dir]'
cmake --build build --target install --parallel [num CPU cores]
ℹ️ Make sure to check out our template C++ project.
To verify the installation works as expected, you can test if the integration project compiles and runs. This is done by running the following command:
cmake -S tests/integration -B build_integration -D'CMAKE_PREFIX_PATH=[path/to/install/dir]'
cmake --build build_integration --target test --parallel [num CPU cores]
Under releases you may find prebuilt library for Windows, for use in either integration method. See Releases
Integration with add_subdirectory is not supported. Add these lines to the CMakeLists.txt of your project:
find_package(depthai CONFIG REQUIRED)
target_link_libraries([my-app] PRIVATE depthai::core)If the install folder is not in a default search path (for example /usr/local on Linux), configure with
-D'CMAKE_PREFIX_PATH=[path/to/install/dir]'.
For vcpkg integration, see the example. It uses a custom branch of DepthAI.
To use the library from another build system (Make, Meson, an IDE project), first install it. Then compile with C++17 against the install:
g++ -std=c++17 main.cpp -o main \
-I[path/to/install/dir]/include -I/usr/include/opencv4 \
-L[path/to/install/dir]/lib -Wl,-rpath,[path/to/install/dir]/lib \
-ldepthai-core -lopencv_core
You do not need -D flags: the install records them in include/depthai/build/definitions.hpp. The OpenCV flags are necessary only if the library has OpenCV support.
We collect some anonymized telemetry to understand how users use the library so we can improve it. This mainly includes which nodes are used most often, how long sessions last, and similar usage information. If you prefer, you can disable telemetry by setting the environment variable DEPTHAI_TELEMETRY=0.
DepthAI v3 does not support Android yet. For RVC2 devices, use DepthAI v2, or open an issue to request Android support in v3.
Many features of the library can be disabled or enabled using CMake options.
One common option when building the library tests and examples is DEPTHAI_VCPKG_INTERNAL_ONLY=OFF which installs a predictable version of OpenCV, PCL and other optional dependencies we also use on the libraries interface.
ℹ️ When
DEPTHAI_VCPKG_INTERNAL_ONLY=OFFis used, the library cannot be installed (apart from being installed in the scope of the vcpkg package manager).
For a full list of options, see cmake/depthaiOptions.cmake file.
The following environment variables can be set to alter default behavior of the library without having to recompile
| Environment variable | Description |
|---|---|
| DEPTHAI_LEVEL | Sets logging verbosity, 'trace', 'debug', 'info', 'warn', 'error' and 'off' |
| XLINK_LEVEL | Sets logging verbosity of XLink library, 'debug'. 'info', 'warn', 'error', 'fatal' and 'off' |
| DEPTHAI_INSTALL_SIGNAL_HANDLER | Set to 0 to disable installing Backward signal handler for stack trace printing |
| DEPTHAI_DEBUGGER | Enables debugger-friendly behavior. ON is equivalent to DEPTHAI_WATCHDOG=0 and DEPTHAI_RPC_READ_TIMEOUT=0. Explicit values of those variables still take precedence. |
| DEPTHAI_WATCHDOG | Sets device watchdog timeout. Useful for debugging (DEPTHAI_WATCHDOG=0), to prevent device reset while the process is paused. |
| DEPTHAI_WATCHDOG_INITIAL_DELAY | Specifies delay after which the device watchdog starts. |
| DEPTHAI_SEARCH_TIMEOUT | Specifies timeout in milliseconds for device searching in blocking functions. |
| DEPTHAI_CONNECT_TIMEOUT | Specifies timeout in milliseconds for establishing a connection to a given device. |
| DEPTHAI_BOOTUP_TIMEOUT | Specifies timeout in milliseconds for waiting the device to boot after sending the binary. |
| DEPTHAI_RECONNECT_TIMEOUT | Specifies timeout in milliseconds for reconnecting to a device after a connection loss. If set to 0, reconnect is disabled. |
| DEPTHAI_PROTOCOL | Restricts default search to the specified protocol. Options: any, usb, tcpip, tcpshd. |
| DEPTHAI_PLATFORM | Restricts default search to the specified platform. Options: any, rvc2, rvc3, rvc4. |
| DEPTHAI_RPC_READ_TIMEOUT | Specifies timeout in milliseconds for reading RPC responses. If 0, wait indefinitely. |
| DEPTHAI_RPC_WRITE_TIMEOUT | Specifies timeout in milliseconds for writing RPC requests. If 0, wait indefinitely. |
| DEPTHAI_DEVICE_MXID_LIST | Restricts default search to the specified MXIDs. Accepts comma separated list of MXIDs. Lists filter results in an "AND" manner and not "OR" |
| DEPTHAI_DEVICE_ID_LIST | Alias to MXID list. Lists filter results in an "AND" manner and not "OR" |
| DEPTHAI_DEVICE_NAME_LIST | Restricts default search to the specified NAMEs. Accepts comma separated list of NAMEs. Lists filter results in an "AND" manner and not "OR". It also looks for NAMEs outside of the host's subnet in case of tcpip. |
| DEPTHAI_DEVICE_BINARY | Overrides device Firmware binary. Mostly for internal debugging purposes. |
| DEPTHAI_DEVICE_RVC4_FWP | Overrides device RVC4 Firmware binary at run time with the firmware package at this path. See also the CMake option DEPTHAI_DEVICE_RVC4_FWP_PATH. |
| DEPTHAI_BOOTLOADER_BINARY_USB | Overrides device USB Bootloader binary. Mostly for internal debugging purposes. |
| DEPTHAI_BOOTLOADER_BINARY_ETH | Overrides device Network Bootloader binary. Mostly for internal debugging purposes. |
| DEPTHAI_ALLOW_FACTORY_FLASHING | Internal use only |
| DEPTHAI_LIBUSB_ANDROID_JAVAVM | JavaVM pointer that is passed to libusb for rootless Android interaction with devices. Interpreted as decimal value of uintptr_t |
| DEPTHAI_CACHE_DIR | Overrides the default DepthAI cache root directory. Default: macOS ~/Library/Caches/depthai, Windows %LOCALAPPDATA%\\depthai\\cache, Linux ${XDG_CACHE_HOME:-~/.cache}/depthai |
| DEPTHAI_CRASHDUMP | Directory in which to save the crash dump. Automatic crash dump collection is disabled if set to 0. |
| DEPTHAI_CRASHDUMP_TIMEOUT | Specifies the duration in milliseconds to wait for device reboot when obtaining a crash dump. Automatic crash dump collection is disabled if set to 0. |
| DEPTHAI_TELEMETRY | Telemetry is enabled by default. Set to 0 or false to disable event capture. |
| DEPTHAI_TELEMETRY_URL | Overrides the telemetry capture URL. |
| DEPTHAI_TELEMETRY_API_KEY | Overrides the telemetry API key. |
| DEPTHAI_DISABLE_CRASHDUMP_COLLECTION | Disables automatic crash dump collection used to improve the library |
| DEPTHAI_DISABLE_STARTUP_NOTIFICATIONS | Startup notifications are enabled by default when CURL support is available. Set to 1 or true to disable fetching and displaying them. |
| DEPTHAI_STARTUP_NOTIFICATIONS_URL | Overrides the startup notification JSON URL. Defaults to https://depthai-releases.luxonis.com/startup_notifications.json. Requires CURL support. |
| DEPTHAI_HUB_EVENTS_BASE_URL | URL for events of the Luxonis Hub |
| DEPTHAI_HUB_API_KEY | API key for the Luxonis Hub |
| DEPTHAI_ZOO_INTERNET_CHECK | (Default) 1 - perform internet check, if available, download the newest model version 0 - skip internet check and use cached model |
| DEPTHAI_ZOO_INTERNET_CHECK_TIMEOUT | (Default) 1000 - timeout in milliseconds for the internet check |
| DEPTHAI_ZOO_CACHE_PATH | (Default) ${DEPTHAI_CACHE_DIR}/models - Folder where cached zoo models are stored |
| DEPTHAI_ZOO_MODELS_PATH | (Default) depthai_models - Folder where zoo model description files are stored |
| DEPTHAI_RECORD | Enables holistic record to the specified directory. |
| DEPTHAI_REPLAY | Replays holistic replay from the specified file or directory. |
| DEPTHAI_PROFILING | Enables runtime profiling of data transfer between the host and connected devices. Set to 1 to enable. Requires DEPTHAI_LEVEL=debug or lower to print. |
| DEPTHAI_PIPELINE_DEBUGGING | Enables pipeline debugging with state dumps. DEPTHAI_LEVEL=trace is required to print the state dumps. |
| DEPTHAI_AUTOCALIBRATION | Runs recalibration of the stereo pair and, by default, flashes successful calibration to non-volatile memory (EEPROM). CONTINUOUS: runs check repetitively; ON_START: runs calibration only at the start of the pipeline; OFF: no recalibration. The same mode can be configured from code with pipeline.setAutoCalibrationMode(...). If this environment variable is set, it overrides the pipeline-set value. AutoCalibration currently initializes only for stereo inputs at 1280x800. |
The library uses clang format to enforce a certain coding style.
If a style check is failing, run the clangformat target, check the output and push changes.
To use this target clang format must be installed, preferably clang-format-18
sudo apt install clang-format-18
or using pip
python -m pip install clang-format==18.1.0
And to apply formatting
cmake --build build --target clangformat
Doxygen is used to generate documentation. Follow doxygen download and install the required binaries for your platform.
After that specify CMake define -D'DEPTHAI_BUILD_DOCS=ON' and build the target doxygen
If CMake does not find an installed OpenCV, give its location with OpenCV_DIR:
cmake -S . -B build -D'OpenCV_DIR=/usr/lib/x86_64-linux-gnu/cmake/opencv4' # Ubuntu
cmake -S . -B build -D'OpenCV_DIR=C:/tools/opencv/build' # Windows, OpenCV from Chocolatey
If the build stops with c++: fatal error: Killed signal terminated program cc1plus, the system ran out of memory.
Use fewer parallel jobs:
cmake --build build --parallel 2
