Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v3_develop' into python-type-mis…
Browse files Browse the repository at this point in the history
…match
  • Loading branch information
borbrudar committed Sep 18, 2024
2 parents 0e3daa6 + d29b922 commit 3eb3d25
Show file tree
Hide file tree
Showing 249 changed files with 12,791 additions and 2,495 deletions.
134 changes: 76 additions & 58 deletions .github/workflows/python-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
python-version: 3.8
- name: Install dependencies
run: |
sudo apt update
python -m pip install --upgrade pip
sudo apt install libusb-1.0-0-dev libopencv-dev libpcl-dev
python -m pip install -r bindings/python/docs/requirements_mkdoc.txt
Expand All @@ -59,70 +60,81 @@ jobs:
retention-days: 1


# TODO(Morato) - re-enable
# # Build and test bindings
# pytest:
# needs: build-docstrings
# strategy:
# matrix:
# os: [ubuntu-latest, windows-latest, macos-latest]
# runs-on: ${{ matrix.os }}
# steps:
# - name: Print home directory
# run: echo Home directory inside container $HOME
# Build and test bindings
pytest:
needs: build-docstrings
strategy:
matrix:
# os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest] # TODO(Morato) - re-enable windows & macos
runs-on: ${{ matrix.os }}
steps:
- name: Print home directory
run: echo Home directory inside container $HOME

# - name: Cache .hunter folder
# if: matrix.os != 'windows-latest'
# uses: actions/cache@v3
# with:
# path: ~/.hunter/
# key: hunter-pytest-${{ matrix.os }}-v3-develop
# - name: Cache .hunter folder
# if: matrix.os == 'windows-latest'
# uses: actions/cache@v3
# with:
# path: C:/.hunter/
# key: hunter-pytest-${{ matrix.os }}-v3-develop
- name: Cache .hunter folder
if: matrix.os != 'windows-latest'
uses: actions/cache@v3
with:
path: ~/.hunter/
key: hunter-pytest-${{ matrix.os }}-v3-develop
- name: Cache .hunter folder
if: matrix.os == 'windows-latest'
uses: actions/cache@v3
with:
path: C:/.hunter/
key: hunter-pytest-${{ matrix.os }}-v3-develop

# - uses: actions/checkout@v3
# with:
# submodules: 'recursive'
- uses: actions/checkout@v3
with:
submodules: 'recursive'

# - uses: actions/download-artifact@v3
# with:
# name: 'docstrings'
# path: bindings/python/docstrings
# - name: Specify docstring to use while building the wheel
# run: echo "DEPTHAI_PYTHON_DOCSTRINGS_INPUT=$PWD/bindings/python/docstrings/depthai_python_docstring.hpp" >> $GITHUB_ENV
- uses: actions/download-artifact@v3
with:
name: 'docstrings'
path: bindings/python/docstrings
- name: Specify docstring to use while building the wheel
run: echo "DEPTHAI_PYTHON_DOCSTRINGS_INPUT=$PWD/bindings/python/docstrings/depthai_python_docstring.hpp" >> $GITHUB_ENV

# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v4
# with:
# python-version: "3.10"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: "3.10"

# - name: Install dependencies (Ubuntu)
# if: matrix.os == 'ubuntu-latest'
# run: |
# python -m pip install --upgrade pip
# sudo apt install libusb-1.0-0-dev
- name: Install dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
python -m pip install --upgrade pip
sudo apt install libusb-1.0-0-dev libopencv-dev
# - name: Install dependencies (MacOS)
# if: matrix.os == 'macos-latest'
# run: |
# python -m pip install --upgrade pip
# brew install libusb
- name: Install dependencies (MacOS)
if: matrix.os == 'macos-latest'
run: |
python -m pip install --upgrade pip
brew install libusb
brew install opencv
# - name: Install pytest
# run: |
# python -m pip install pytest numpy
- name: Setup cmake
if: matrix.os == 'macos-latest'
uses: jwlawson/actions-setup-cmake@v1.13

# - name: Compile
# run: |
# cmake -S . -B build -DDEPTHAI_BUILD_PYTHON=ON -D CMAKE_BUILD_TYPE=Release -D DEPTHAI_PYTHON_DOCSTRINGS_INPUT=$PWD/bindings/python/docstrings/depthai_python_docstring.hpp -D DEPTHAI_PYTHON_ENABLE_TESTS=ON
# cmake --build build --parallel 4
# - name: Test
# run: |
# cmake --build build --target pytest --config Release
- name: Install dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install opencv
echo "OpenCV_DIR=C:\tools\opencv\build" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Install pytest
run: |
python -m pip install pytest numpy opencv-python
- name: Compile
run: |
cmake -S . -B build -DDEPTHAI_BUILD_PYTHON=ON -D CMAKE_BUILD_TYPE=Release -D DEPTHAI_PYTHON_DOCSTRINGS_INPUT=$PWD/bindings/python/docstrings/depthai_python_docstring.hpp -D DEPTHAI_PYTHON_ENABLE_TESTS=ON
cmake --build build --parallel 4
- name: Test
run: |
cmake --build build --target pytest --config Release
# # This job builds wheels for armhf arch (RPi)
Expand Down Expand Up @@ -380,6 +392,9 @@ jobs:
image: mmorato/depthai-manylinux2014:0.4 # TODO(mmorato) temporary location, push to luxonis namespace
env:
PLAT: manylinux2014_x86_64
strategy:
matrix:
python-set: ["7..9", "10..12"]
env:
# workaround required for cache@v3, https://github.com/actions/cache/issues/1428
# to be removed when upgrading the manylinux image
Expand Down Expand Up @@ -429,7 +444,7 @@ jobs:
/opt/python/cp38-cp38/bin/python3.8 setup.py sdist --formats=gztar
mv dist/* wheelhouse/audited/
- name: Build wheels
run: cd bindings/python && for PYBIN in /opt/python/cp3{7..12}*/bin; do "${PYBIN}/pip" wheel . -w ./wheelhouse/ --verbose; done
run: cd bindings/python && for PYBIN in /opt/python/cp3{${{ matrix.python-set }}}*/bin; do "${PYBIN}/pip" wheel . -w ./wheelhouse/ --verbose; done
- name: Audit wheels
run: cd bindings/python && for whl in wheelhouse/*.whl; do auditwheel repair "$whl" --plat $PLAT -w wheelhouse/audited/; done
- name: Archive wheel artifacts
Expand Down Expand Up @@ -457,6 +472,9 @@ jobs:
# Mount local hunter cache directory, instead of transfering to Github and back
volumes:
- /.hunter:/github/home/.hunter
strategy:
matrix:
python-set: ["7..9", "10..12"]
env:
# workaround required for cache@v3, https://github.com/actions/cache/issues/1428
# to be removed when upgrading the manylinux image
Expand Down Expand Up @@ -495,7 +513,7 @@ jobs:
if: startsWith(github.ref, 'refs/tags/v') != true
run: echo "BUILD_COMMIT_HASH=${{github.sha}}" >> $GITHUB_ENV
- name: Building wheels
run: cd bindings/python && for PYBIN in /opt/python/cp3{7..12}*/bin; do "${PYBIN}/pip" wheel . -w ./wheelhouse/ --verbose; done
run: cd bindings/python && for PYBIN in /opt/python/cp3{${{ matrix.python-set }}}*/bin; do "${PYBIN}/pip" wheel . -w ./wheelhouse/ --verbose; done
- name: Auditing wheels
run: cd bindings/python && for whl in wheelhouse/*.whl; do auditwheel repair "$whl" --plat $PLAT -w wheelhouse/audited/; done
- name: Archive wheel artifacts
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "bindings/python/external/xtensor-python"]
path = bindings/python/external/xtensor-python
url = https://github.com/xtensor-stack/xtensor-python.git
[submodule "3rdparty/pybind11_opencv_numpy"]
path = bindings/python/external/pybind11_opencv_numpy
url = https://github.com/luxonis/pybind11_opencv_numpy.git
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ endif()
# Create depthai project
project(depthai VERSION "3.0.0" LANGUAGES CXX C)
set(DEPTHAI_PRE_RELEASE_TYPE "alpha") # Valid options are "alpha", "beta", "rc", ""
set(DEPTHAI_PRE_RELEASE_VERSION "0")
set(DEPTHAI_PRE_RELEASE_VERSION "2")

# Set DEPTHAI_VERSION universally, not conditionally
set(DEPTHAI_VERSION ${PROJECT_VERSION}-${DEPTHAI_PRE_RELEASE_TYPE}.${DEPTHAI_PRE_RELEASE_VERSION})
Expand Down Expand Up @@ -266,6 +266,7 @@ set(TARGET_CORE_SOURCES
# depthai-bootloader-shared sources
"${DEPTHAI_BOOTLOADER_SHARED_SOURCES}"
# sources
src/common/ModelType.cpp
src/device/Device.cpp
src/device/DeviceBase.cpp
src/device/DeviceBootloader.cpp
Expand All @@ -290,6 +291,7 @@ set(TARGET_CORE_SOURCES
src/pipeline/node/Sync.cpp
src/pipeline/node/NeuralNetwork.cpp
src/pipeline/node/ImageManip.cpp
src/pipeline/node/ImageManipV2.cpp
src/pipeline/node/Warp.cpp
src/pipeline/node/VideoEncoder.cpp
src/pipeline/node/DetectionNetwork.cpp
Expand Down Expand Up @@ -320,6 +322,7 @@ set(TARGET_CORE_SOURCES
src/pipeline/datatype/ImgTransformations.cpp
src/pipeline/datatype/EncodedFrame.cpp
src/pipeline/datatype/ImageManipConfig.cpp
src/pipeline/datatype/ImageManipConfigV2.cpp
src/pipeline/datatype/CameraControl.cpp
src/pipeline/datatype/NNData.cpp
src/pipeline/datatype/ImgDetections.cpp
Expand All @@ -344,6 +347,7 @@ set(TARGET_CORE_SOURCES
src/pipeline/datatype/MessageGroup.cpp
src/pipeline/datatype/TransformData.cpp
src/utility/H26xParsers.cpp
src/utility/ImageManipV2Impl.cpp
src/utility/Initialization.cpp
src/utility/Resources.cpp
src/utility/Path.cpp
Expand All @@ -368,8 +372,6 @@ set(TARGET_CORE_SOURCES
src/utility/ArchiveUtil.cpp
src/nn_archive/NNArchive.cpp
src/nn_archive/NNArchiveConfig.cpp
src/nn_archive/NNArchiveBlob.cpp
src/nn_archive/NNArchiveConfigHelper.cpp
src/modelzoo/NNModelDescription.cpp
src/modelzoo/Zoo.cpp
)
Expand Down Expand Up @@ -655,6 +657,7 @@ target_link_libraries(${TARGET_CORE_NAME}
httplib::httplib
mp4v2::mp4v2
semver::semver
apriltag::apriltag
)

if(DEPTHAI_ENABLE_CURL)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ The following environment variables can be set to alter default behavior of the
| 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. |
| 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_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" |
Expand All @@ -187,6 +188,7 @@ The following environment variables can be set to alter default behavior of the
| DEPTHAI_CRASHDUMP | Directory in which to save the crash dump. |
| DEPTHAI_CRASHDUMP_TIMEOUT | Specifies the duration in seconds to wait for device reboot when obtaining a crash dump. Crash dump retrieval disabled if 0. |
| DEPTHAI_DISABLE_FEEDBACK | Disables crash dump and pipeline schema collection used to improve the library |
| DEPTHAI_HUB_API_KEY | (Default) API key for the Luxonis Hub |


## Running tests
Expand Down
1 change: 1 addition & 0 deletions bindings/js/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ EMSCRIPTEN_BINDINGS(depthai_js) {
.value("EncodedFrame", dai::DatatypeEnum::EncodedFrame)
.value("NNData", dai::DatatypeEnum::NNData)
.value("ImageManipConfig", dai::DatatypeEnum::ImageManipConfig)
.value("ImageManipConfigV2", dai::DatatypeEnum::ImageManipConfig)
.value("CameraControl", dai::DatatypeEnum::CameraControl)
.value("ImgDetections", dai::DatatypeEnum::ImgDetections)
.value("SpatialImgDetections", dai::DatatypeEnum::SpatialImgDetections)
Expand Down
11 changes: 11 additions & 0 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ set(SOURCE_LIST
src/nn_archive/NNArchiveBindings.cpp
src/log/LogBindings.cpp
src/VersionBindings.cpp
src/common/ModelTypeBindings.cpp

src/pipeline/node/NodeBindings.cpp

Expand All @@ -84,6 +85,7 @@ set(SOURCE_LIST
src/pipeline/node/NeuralNetworkBindings.cpp
src/pipeline/node/VideoEncoderBindings.cpp
src/pipeline/node/ImageManipBindings.cpp
src/pipeline/node/ImageManipV2Bindings.cpp
src/pipeline/node/SPIOutBindings.cpp
src/pipeline/node/SPIInBindings.cpp
src/pipeline/node/DetectionNetworkBindings.cpp
Expand Down Expand Up @@ -119,6 +121,7 @@ set(SOURCE_LIST
src/pipeline/datatype/FeatureTrackerConfigBindings.cpp
src/pipeline/datatype/ToFConfigBindings.cpp
src/pipeline/datatype/ImageManipConfigBindings.cpp
src/pipeline/datatype/ImageManipConfigV2Bindings.cpp
src/pipeline/datatype/ImgDetectionsBindings.cpp
src/pipeline/datatype/ImgFrameBindings.cpp
src/pipeline/datatype/EncodedFrameBindings.cpp
Expand All @@ -144,6 +147,11 @@ set(SOURCE_LIST
src/modelzoo/NNModelDescriptionBindings.cpp
src/modelzoo/ZooBindings.cpp
)
if(DEPTHAI_MERGED_TARGET)
list(APPEND SOURCE_LIST
external/pybind11_opencv_numpy/ndarray_converter.cpp
)
endif()

if(DEPTHAI_BASALT_SUPPORT)
list(APPEND SOURCE_LIST
Expand Down Expand Up @@ -260,6 +268,9 @@ endif()

# Add include directory
target_include_directories(${TARGET_NAME} PRIVATE src ${DOCSTRINGS_INCLUDE_PLACEHOLDER_DIR})
if(DEPTHAI_MERGED_TARGET)
target_include_directories(${TARGET_NAME} PRIVATE external/pybind11_opencv_numpy)
endif()

set(DEPTHAI_LINK_TARGET depthai::core)
if(NOT DEPTHAI_MERGED_TARGET)
Expand Down
1 change: 1 addition & 0 deletions bindings/python/external/pybind11_opencv_numpy
Submodule pybind11_opencv_numpy added at 45594f
3 changes: 3 additions & 0 deletions bindings/python/src/DatatypeBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void bind_edgedetectorconfig(pybind11::module& m, void* pCallstack);
void bind_featuretrackerconfig(pybind11::module& m, void* pCallstack);
void bind_tofconfig(pybind11::module& m, void* pCallstack);
void bind_imagemanipconfig(pybind11::module& m, void* pCallstack);
void bind_imagemanipconfigv2(pybind11::module& m, void* pCallstack);
void bind_imgdetections(pybind11::module& m, void* pCallstack);
void bind_imgframe(pybind11::module& m, void* pCallstack);
void bind_encodedframe(pybind11::module& m, void* pCallstack);
Expand Down Expand Up @@ -45,6 +46,7 @@ void DatatypeBindings::addToCallstack(std::deque<StackFunction>& callstack) {
callstack.push_front(bind_featuretrackerconfig);
callstack.push_front(bind_tofconfig);
callstack.push_front(bind_imagemanipconfig);
callstack.push_front(bind_imagemanipconfigv2);
callstack.push_front(bind_imgdetections);
callstack.push_front(bind_imgframe);
callstack.push_front(bind_encodedframe);
Expand Down Expand Up @@ -91,6 +93,7 @@ void DatatypeBindings::bind(pybind11::module& m, void* pCallstack){
.value("EncodedFrame", DatatypeEnum::EncodedFrame)
.value("NNData", DatatypeEnum::NNData)
.value("ImageManipConfig", DatatypeEnum::ImageManipConfig)
.value("ImageManipConfigV2", DatatypeEnum::ImageManipConfigV2)
.value("CameraControl", DatatypeEnum::CameraControl)
.value("ImgDetections", DatatypeEnum::ImgDetections)
.value("SpatialImgDetections", DatatypeEnum::SpatialImgDetections)
Expand Down
14 changes: 10 additions & 4 deletions bindings/python/src/DeviceBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// hedley
#include <hedley/hedley.h>
// STL Bind
#include <pybind11/pytypes.h>
#include <pybind11/stl_bind.h>

PYBIND11_MAKE_OPAQUE(std::unordered_map<std::int8_t, dai::BoardConfig::GPIO>);
Expand Down Expand Up @@ -201,6 +202,7 @@ void DeviceBindings::bind(pybind11::module& m, void* pCallstack){
py::class_<BoardConfig::USB> boardConfigUsb(boardConfig, "USB", DOC(dai, BoardConfig, USB));
py::class_<BoardConfig::Network> boardConfigNetwork(boardConfig, "Network", DOC(dai, BoardConfig, Network));
py::class_<BoardConfig::GPIO> boardConfigGpio(boardConfig, "GPIO", DOC(dai, BoardConfig, GPIO));
py::enum_<dai::Device::ReconnectionStatus> enumReconnectionStatus(device, "ReconnectionStatus", DOC(dai, DeviceBase, ReconnectionStatus));
py::enum_<BoardConfig::GPIO::Mode> boardConfigGpioMode(boardConfigGpio, "Mode", DOC(dai, BoardConfig, GPIO, Mode));
py::enum_<BoardConfig::GPIO::Direction> boardConfigGpioDirection(boardConfigGpio, "Direction", DOC(dai, BoardConfig, GPIO, Direction));
py::enum_<BoardConfig::GPIO::Level> boardConfigGpioLevel(boardConfigGpio, "Level", DOC(dai, BoardConfig, GPIO, Level));
Expand Down Expand Up @@ -335,11 +337,14 @@ void DeviceBindings::bind(pybind11::module& m, void* pCallstack){
;

// Bind Platform
platform
.value("RVC2", Platform::RVC2, DOC(dai, Platform, RVC2))
platform.value("RVC2", Platform::RVC2, DOC(dai, Platform, RVC2))
.value("RVC3", Platform::RVC3, DOC(dai, Platform, RVC3))
.value("RVC4", Platform::RVC4, DOC(dai, Platform, RVC4))
;
.value("RVC4", Platform::RVC4, DOC(dai, Platform, RVC4));

// Bind Device::ReconnectionStatus
enumReconnectionStatus.value("RECONNECT_FAILED", Device::ReconnectionStatus::RECONNECT_FAILED);
enumReconnectionStatus.value("RECONNECTED", Device::ReconnectionStatus::RECONNECTED);
enumReconnectionStatus.value("RECONNECTING", Device::ReconnectionStatus::RECONNECTING);

// Platform - string conversion
m.def("platform2string", &platform2string, DOC(dai, platform2string));
Expand Down Expand Up @@ -447,6 +452,7 @@ void DeviceBindings::bind(pybind11::module& m, void* pCallstack){
})
.def("close", [](DeviceBase& d) { py::gil_scoped_release release; d.close(); }, "Closes the connection to device. Better alternative is the usage of context manager: `with depthai.Device(pipeline) as device:`")
.def("isClosed", [](DeviceBase& d) { py::gil_scoped_release release; return d.isClosed(); }, DOC(dai, DeviceBase, isClosed))
.def("setMaxReconnectionAttempts", &DeviceBase::setMaxReconnectionAttempts, py::arg("maxAttempts"), py::arg("callback") = py::none(), DOC(dai, DeviceBase, setMaxReconnectionAttempts))

//dai::Device methods
//static
Expand Down
Loading

0 comments on commit 3eb3d25

Please sign in to comment.