• Stars
    star
    357
  • Rank 119,149 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

DepthAI Python Library

DepthAI Python Library

License: MIT Python Wheel CI

Python bindings for C++ depthai-core library

Documentation

Documentation is available over at Luxonis DepthAI API

Installation

Prebuilt wheels are available in Luxonis repository Make sure pip is upgraded

python3 -m pip install -U pip
python3 -m pip install --extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local/ depthai

Building from source

Dependencies

  • cmake >= 3.4
  • C++14 compiler (clang, gcc, msvc, ...)
  • Python3

Along these, dependencies of depthai-core are also required See: depthai-core dependencies

Building

The first time you build, the repository submodules need be initialized:

git submodule update --init --recursive

# Tip: You can ask Git to do that automatically:
git config submodule.recurse true

Later submodules also need to be updated.

Local build with pip

To build and install using pip:

python3 -m pip install .

Add parameter -v to see the output of the building process.

Wheel with pip

To build a wheel, execute the following

python3 -m pip wheel . -w wheelhouse

Shared library

To build a shared library from source perform the following:

ℹī¸ To speed up build times, use cmake --build build --parallel [num CPU cores] (CMake >= 3.12). For older versions use: Linux/macOS: cmake --build build -- -j[num CPU cores], MSVC: cmake --build build -- /MP[num CPU cores]

cmake -H. -Bbuild
cmake --build build

To specify custom Python executable to build for, use cmake -H. -Bbuild -D PYTHON_EXECUTABLE=/full/path/to/python.

Common issues

  • Many build fails due to missing dependencies. This also happens when submodules are missing or outdated (git submodule update --recursive).
  • If libraries and headers are not in standard places, or not on the search paths, CMake reports it cannot find what it needs (e.g. libusb). CMake can be hinted at where to look, for exmpale: CMAKE_LIBRARY_PATH=/opt/local/lib CMAKE_INCLUDE_PATH=/opt/local/include pip install .
  • Some distribution installers may not get the desired library. For example, an install on a RaspberryPi failed, missing libusb, as the default installation with APT led to v0.1.3 at the time, whereas the library here required v1.0.

Running tests

To run the tests build the library with the following options

git submodule update --init --recursive
cmake -H. -Bbuild -D DEPTHAI_PYTHON_ENABLE_TESTS=ON -D DEPTHAI_PYTHON_ENABLE_EXAMPLES=ON -D DEPTHAI_PYTHON_TEST_EXAMPLES=ON
cmake --build build

Then navigate to build folder and run ctest

cd build
ctest

To test a specific example/test with a custom timeout (in seconds) use following:

TEST_TIMEOUT=0 ctest -R "01_rgb_preview" --verbose

If TEST_TIMEOUT=0, the test will run until stopped or it ends.

Tested platforms

  • Windows 10, Windows 11
  • Ubuntu 18.04, 20.04, 22.04;
  • Raspbian 10;
  • macOS 10.14.6, 10.15.4;

Building documentation

  • Using Docker (with Docker Compose)

    cd docs
    sudo docker-compose build
    sudo docker-compose up
    

    ℹī¸ You can leave out the sudo if you have added your user to the docker group (or are using rootless docker). Then open http://localhost:8000.

    This docker container will watch changes in the docs/source directory and rebuild the docs automatically

  • Linux

    First, please install the required dependencies

    Then run the following commands to build the docs website

    python3 -m pip install -U pip
    python3 -m pip install -r docs/requirements.txt
    cmake -H. -Bbuild -D DEPTHAI_BUILD_DOCS=ON -D DEPTHAI_PYTHON_BUILD_DOCS=ON
    cmake --build build --target sphinx
    python3 -m http.server --bind 0.0.0.0 8000 --directory build/docs/sphinx
    

    Then open http://localhost:8000.

    This will build documentation based on current sources, so if some new changes will be made, run this command in a new terminal window to update the website source

    cmake --build build --target sphinx
    

    Then refresh your page - it should load the updated website that was just built

Troubleshooting

Relocation link error

Build failure on Ubuntu 18.04 ("relocation ..." link error) with gcc 7.4.0 (default) - issue #3

  • the solution was to upgrade gcc to version 8:

    sudo apt install g++-8
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 70
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 70
    

Hunter

Hunter is a CMake-only dependency manager for C/C++ projects.

If you are stuck with error message which mentions external libraries (subdirectory of .hunter) like the following:

/usr/bin/ld: /home/[user]/.hunter/_Base/062a19a/ccfed35/a84a713/Install/lib/liblzma.a(stream_flags_decoder.c.o): warning: relocation against `lzma_footer_magic' in read-only section `.text'

Try erasing the Hunter cache folder.

Linux/MacOS:

rm -r ~/.hunter

Windows:

del C:/.hunter

or

del C:/[user]/.hunter

LTO - link time optimization

If following message appears:

lto1: internal compiler error: in add_symbol_to_partition_1, at lto/lto-partition.c:152
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-10/README.Bugs> for instructions.
lto-wrapper: fatal error: /usr/bin/c++ returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/depthai.dir/build.make:227: depthai.cpython-38-x86_64-linux-gnu.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:98: CMakeFiles/depthai.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

One fix is to update linker: (In case you are on Ubuntu 20.04: /usr/bin/ld --version: 2.30)

# Add to the end of /etc/apt/sources.list:

echo "deb http://ro.archive.ubuntu.com/ubuntu groovy main" >> /etc/apt/sources.list

# Replace ro with your countries local cache server (check the content of the file to find out which is)
# Not mandatory, but faster

sudo apt update
sudo apt install binutils

# Should upgrade to 2.35.1
# Check version:
/usr/bin/ld --version
# Output should be: GNU ld (GNU Binutils for Ubuntu) 2.35.1
# Revert /etc/apt/sources.list to previous state (comment out line) to prevent updating other packages.
sudo apt update

Another option is to use clang compiler:

sudo apt install clang-10
mkdir build && cd build
CC=clang-10 CXX=clang++-10 cmake ..
cmake --build . --parallel

More Repositories

1

depthai

DepthAI Python API utilities, examples, and tutorials.
Python
933
star
2

depthai-experiments

Experimental projects we've done with DepthAI.
Jupyter Notebook
829
star
3

depthai-hardware

Altium Designs for DepthAI Carrier Boards
HTML
447
star
4

depthai-ros

Official ROS Driver for DepthAI Sensors.
C++
255
star
5

depthai-core

DepthAI C++ Library
C++
234
star
6

depthai-unity

DepthAI Unity Library, Unity projects and examples (OAK For Unity)
C#
200
star
7

depthai-ml-training

Some Example Neural Models that we've trained along with the training scripts
Jupyter Notebook
119
star
8

datadreamer

Creation of annotated datasets from scratch using Generative AI and Foundation Computer Vision models
Python
77
star
9

depthai-gui

DepthAI Pipeline Builder GUI
Python
75
star
10

depthai-ros-examples

Python
41
star
11

depthai-tutorials

Source code for DepthAI tutorials published @ https://docs.luxonis.com
Python
40
star
12

depthai-model-zoo

DepthAI Model Zoo is a collection of open-source neural network models and datasets created and maintained by DepthAI developers and community
Python
35
star
13

rae-ros

Implementation of RAE ROS and gazebo stack
Python
32
star
14

esp32-spi-message-demo

ESP32 reference app for interfacing with DepthAI over SPI
C++
31
star
15

tools

Various tools for OAK-D camera
Jupyter Notebook
28
star
16

depthai-docs-website

The documentation site for Luxonis DepthAI
CSS
26
star
17

Factory-calibration-DepthAI

Factory Calibration for DepthAI Stereo-capable models.
Python
17
star
18

depthai-shared

DepthAI Shared code and data
C++
16
star
19

blobconverter

Web-based tool to convert model into MyriadX blob
Python
15
star
20

depthai-core-example

CMake C++ example project using depthai library
CMake
14
star
21

models

Repository of lightweight models for classification, object detection, segmentation and more. Deployable to OAK-D, OpenVINO, and ONNX.
Python
14
star
22

luxonis-ml

Luxonis ML library which abstracts logging, tracking, and other useful functionalities.
Python
13
star
23

XLink

A cross-platform library for communicating with devices over various physical links.
C
12
star
24

DepthAI-PyFlow

OUTDATED, see here - https://github.com/luxonis/depthai-gui
Python
11
star
25

yolo2openvino

YoloV3, YoloV4, YoloV3-tiny, and YoloV4-tiny conversion to Tensorflow and OpenVINO.
Python
10
star
26

luxonis-train

Training framework for easy creation, training and exporting of deep learning models.
Python
10
star
27

depthai-docker

Python
8
star
28

modelconverter

Model converter for Luxonis' cameras. Convert your model from ONNX, TF, ... to a model compatible with any generation of Luxonis camera.
Python
8
star
29

remote-monitoring

JavaScript
7
star
30

depthai-poe-webapp

DepthAI WebApp for PoE devices
Python
7
star
31

robothub-images

Shell
6
star
32

robothub-examples

Python
4
star
33

depthai-spi-api

C++
4
star
34

robothub-public-apps

Python
3
star
35

depthai-boards

Files with hardware descriptions for depthai boards
Python
3
star
36

simulation

3
star
37

depthai-calibration

Python
2
star
38

tusb926x-flash-burner

TUSB926x modern libusb/hidapi Linux flasher
C++
2
star
39

depthai-ros-release

Release repository of depthai-ros
2
star
40

depthai-spi-library

DepthAI SPI Library
C
2
star
41

depthai-bootloader-shared

Shared code and data for depthai-bootloader
C++
2
star
42

depthai-nodes

Python nodes for on-host depthai augmentation.
Python
2
star
43

python-api-analyzer-to-json

Python
1
star
44

robothub

Python
1
star
45

SBR

Library and utility to view and manipulate SBR images
C
1
star
46

depthai-node

CMake
1
star
47

rp2040_u2if

Interface with RP2040 running U2IF FW
Python
1
star
48

rae-unity

RAE Unity plugin and Simulation
1
star