DepthAI Python

repository·main·Indexed 19 days ago

https://github.com/luxonis/depthai-python

Python bindings for the C++ depthai-core library, enabling developers to interface with Luxonis depth cameras and AI hardware. Includes instructions for installation via pip or from source, environment setup, building documentation, and running tests. Provides utilities such as device_manager.py for bootloader configuration and cam_test.py for camera functionality testing.

Tokens
1.6K
Snippets
9
Records
11
Agent score
65%

What's inside depthai-python

  1. Build DepthAI Python documentation

    main

    You can build the documentation website using either Docker or a native Linux setup.

    Using Docker

    This method uses Docker Compose to watch the docs/source directory and rebuild automatically.

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

    Access the docs at http://localhost:8000.

    Using Linux (Native)

    1. Install dependencies and requirements:
      python3 -m pip install -U pip
      python3 -m pip install -r docs/requirements.txt
    2. Build the Sphinx documentation:
      cmake -H. -Bbuild -D DEPTHAI_BUILD_DOCS=ON -D DEPTHAI_PYTHON_BUILD_DOCS=ON
      cmake --build build --target sphinx
    3. Serve the documentation:
      python3 -m http.server --bind 0.0.0.0 8000 --directory build/docs/sphinx
    4. To update the website after making changes, run:
      cmake --build build --target sphinx
  2. Build a bundled executable for Cam Test

    main

    You can build a bundled executable for cam_test.py using pyinstaller. The resulting executable will be located in the dist/cam_test folder.

    Prerequisites: Install pyinstaller via pip:

    • Linux/macOS: python3 -m pip install pyinstaller
    • Windows: python -m pip install pyinstaller

    Build Command:

    pyinstaller -w cam_test.py --hidden-import PyQt5.sip
  3. Install DepthAI Python via pip

    main

    To install the prebuilt wheels for the DepthAI Python bindings, first ensure your pip is upgraded, then install depthai using the Luxonis artifact repository as an extra index URL.

    Note: This method installs the v2.x.y branch. For v3.x.y (which adds RVC4 support), the bindings are integrated directly into the depthai-core repository.

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

    main

    To run the built-in tests, you must build the library with specific CMake flags enabled to include tests and examples.

    1. Build with test flags:
      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
    2. Execute tests using `ctest`:
       ```bash
    cd build
    ctest

    To run a specific test (e.g., 01_rgb_preview) with a custom timeout, use the TEST_TIMEOUT environment variable. Setting TEST_TIMEOUT=0 allows the test to run until it naturally ends or is manually stopped.

    cd build
    TEST_TIMEOUT=0 ctest -R "01_rgb_preview" --verbose
  5. Build DepthAI Python from source

    main

    Building from source requires initializing submodules first.

    Prerequisites

    • cmake >= 3.4
    • C++14 compiler (clang, gcc, msvc, etc.)
    • Python3
    • depthai-core dependencies

    Build Steps

    1. Initialize submodules:

      git submodule update --init --recursive
    2. Build and install locally using pip:

      python3 -m pip install .

      (Use -v to see build output)

    3. (Optional) Build a wheel:

      python3 -m pip wheel . -w wheelhouse

    Building a Shared Library

    To build a shared library manually using CMake:

    cmake -H. -Bbuild
    cmake --build build

    To specify a custom Python executable:

    cmake -H. -Bbuild -D PYTHON_EXECUTABLE=/full/path/to/python
    git submodule update --init --recursive
    python3 -m pip install .
  6. Set up the environment for DepthAI Python examples

    main

    Before running the provided usage examples, you must install the necessary dependencies using the included requirements script.

    Run the following command in your terminal to prepare the environment:

    python3 install_requirements.py
  7. Build a standalone executable for Device Manager

    main

    You can package device_manager.py into a single standalone executable using pyinstaller.

    Prerequisites: Install pyinstaller via pip:

    • Linux/macOS: python3 -m pip install pyinstaller
    • Windows: python -m pip install pyinstaller

    Build Command:

    pyinstaller --onefile -w --icon=assets/icon.ico --add-data="assets/icon.ico;assets" --add-data="assets/icon.png;assets" device_manager.py

    Options:

    • Use --runtime-tmpdir [path or .] to specify a custom location for the temporary directory created at runtime.
  8. Troubleshoot DepthAI Python build issues

    main

    If you encounter a relocation link error with gcc 7.4.0, upgrade to g++-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 Cache Errors

    If you see errors regarding external libraries in the .hunter subdirectory, clear the Hunter cache:

    • Linux/MacOS: rm -r ~/.hunter
    • Windows: del C:/.hunter or del C:/[user]/.hunter

    If you encounter lto1: internal compiler error, you can try:

    1. Updating the linker (Ubuntu 20.04): Add the groovy repository to /etc/apt/sources.list, run sudo apt update && sudo apt install binutils, and verify the version is 2.35.1 or higher.
    2. Using Clang:
      sudo apt install clang-10
      mkdir build && cd build
      CC=clang-10 CXX=clang++-10 cmake ..
      cmake --build . --parallel