Skip to content

Commit

Permalink
Merge branch 'release_2.17.4' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed Sep 19, 2022
2 parents c816cb4 + a12bad4 commit 907b8c0
Show file tree
Hide file tree
Showing 26 changed files with 1,199 additions and 79 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/stability.workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: DepthAI Core HIL Stability

on:
workflow_dispatch:
push:
branches:
- main
- develop
tags:
- 'v*'
pull_request:
branches:
- main
- develop

# Only allow latest run on same branch to be tested
concurrency:
group: ci-stability-${{ github.ref }}-1
cancel-in-progress: true

jobs:

# Testing
test:
runs-on: ['self-hosted', 'hil-stability', 'linux']
timeout-minutes: 1450 # 24h & 10minutes
steps:
- name: Cache .hunter folder
uses: actions/cache@v2
with:
path: $HOME/.hun_vanilla
key: hunter-linux-stability-vanilla
- uses: actions/checkout@v2
with:
submodules: 'recursive'

# TODO also modify above hunter key to 'asan'
# - name: Specify ASAN toolchain path
# run: echo "CMAKE_TOOLCHAIN_PATH=$PWD/cmake/toolchain/asan.cmake" >> $GITHUB_ENV

# - name: Configure, Build and Test
# run: |
# cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D HUNTER_ROOT=$HOME/.hun_vanilla -D DEPTHAI_BUILD_TESTS=ON
# cmake --build build --parallel 8 --config Release --target stability_stress_test
# cd build
# ../ci/stability_stress_test_combined.sh

# Release build
- name: Configure, Build and Test
run: |
cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D HUNTER_ROOT=$HOME/.hun_vanilla -D DEPTHAI_BUILD_TESTS=ON
cmake --build build --parallel 8 --config Release --target stability_stress_test
cd build
../ci/stability_stress_test_combined.sh 86400
20 changes: 14 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if(WIN32)
endif()

# Create depthai project
project(depthai VERSION "2.17.3" LANGUAGES CXX C)
project(depthai VERSION "2.17.4" LANGUAGES CXX C)
get_directory_property(has_parent PARENT_DIRECTORY)
if(has_parent)
set(DEPTHAI_VERSION ${PROJECT_VERSION} PARENT_SCOPE)
Expand Down Expand Up @@ -431,13 +431,14 @@ target_link_libraries(${TARGET_CORE_NAME}
ZLIB::zlib
)

# Add compile definitions
# Add compile & CMake definitions
set(DEPTHAI_DEVICE_VERSION "${DEPTHAI_DEVICE_SIDE_COMMIT}")
target_compile_definitions(${TARGET_CORE_NAME}
PRIVATE
# XLink required define
__PC__
# Add depthai-device version
DEPTHAI_DEVICE_VERSION="${DEPTHAI_DEVICE_SIDE_COMMIT}"
DEPTHAI_DEVICE_VERSION="${DEPTHAI_DEVICE_VERSION}"
# Add depthai-bootloader version
DEPTHAI_BOOTLOADER_VERSION="${DEPTHAI_BOOTLOADER_VERSION}"
)
Expand All @@ -454,7 +455,7 @@ if(DEPTHAI_USB2_PATCH_ONLY_MODE)
endif()

# Helper function
function(add_runtime_dependencies depending_target dependency)
macro(add_runtime_dependencies depending_target dependency)
if(WIN32)
if(TARGET ${dependency})
get_property(imported_configs TARGET ${dependency} PROPERTY IMPORTED_CONFIGURATIONS)
Expand All @@ -465,13 +466,16 @@ function(add_runtime_dependencies depending_target dependency)
endforeach()
endif()
file(GLOB depthai_dll_libraries "${HUNTER_INSTALL_PREFIX}/bin/*.dll")
# Create a list of required dll files
set(required_dll_files ${dlls} ${depthai_dll_libraries})
# Copy the required dlls
add_custom_command(TARGET ${depending_target} POST_BUILD COMMAND
${CMAKE_COMMAND} -E copy_if_different ${dlls} ${depthai_dll_libraries} $<TARGET_FILE_DIR:${depending_target}>
${CMAKE_COMMAND} -E copy_if_different ${required_dll_files} $<TARGET_FILE_DIR:${depending_target}>
COMMAND_EXPAND_LISTS
)
message(STATUS "Required dlls for core are: ${required_dll_files}")
endif()
endfunction()
endmacro()
# Add libusb dll in build time
add_runtime_dependencies(${TARGET_CORE_NAME} usb-1.0)

Expand Down Expand Up @@ -653,6 +657,10 @@ if(DEPTHAI_INSTALL)
if(NOT DEPTHAI_BINARIES_RESOURCE_COMPILE)
install(DIRECTORY "${DEPTHAI_RESOURCES_OUTPUT_DIR}/" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
endif()
# Install any required dll files
if(DEFINED required_dll_files)
install(FILES ${required_dll_files} DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()

# Install export group (information about targets)
install(EXPORT ${PROJECT_EXPORT_GROUP}
Expand Down
38 changes: 38 additions & 0 deletions ci/stability_stress_test_combined.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Cleanup in case the script dies
cleanup() {
# kill all processes whose parent is this process
pkill -P $$
}

for sig in INT QUIT HUP TERM; do
trap "
cleanup
trap - $sig EXIT
kill -s $sig "'"$$"' "$sig"
done
trap cleanup EXIT

# Print timeout if set, otherwise use default
echo "Timeout set to: $1"

# Run USB & PoE stability stress test
DEPTHAI_PROTOCOL=usb timeout $(($1+30)) ./tests/stability_stress_test $1 &
jobUsb=$!
DEPTHAI_PROTOCOL=tcpip timeout $(($1+30)) ./tests/stability_stress_test $1 &
jobTcpip=$!

# Wait for tests and save result code
wait $jobUsb ; resultUsb=$?
wait $jobTcpip ; resultTcpip=$?

# Print results
echo "Stability test USB: $resultUsb"
echo "Stability test PoE: $resultTcpip"

# If both tests concluded successfully, exit with code 0
if [[ "$resultUsb" == "0" ]] && [[ "$resultTcpip" == "0" ]]; then
echo "Success!"
exit 0
fi
echo "Failed!"
exit 1
2 changes: 1 addition & 1 deletion cmake/Depthai/DepthaiDeviceSideConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot")

# "full commit hash of device side binary"
set(DEPTHAI_DEVICE_SIDE_COMMIT "602822fe9eaca68a72c666497dc4979b29291b3e")
set(DEPTHAI_DEVICE_SIDE_COMMIT "1a59c80266cd7a30ba874aa8d4a8277e0bf161ec")

# "version if applicable"
set(DEPTHAI_DEVICE_SIDE_VERSION "")
4 changes: 2 additions & 2 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ hunter_config(
hunter_config(
XLink
VERSION "luxonis-2021.4.2-develop"
URL "https://github.com/luxonis/XLink/archive/b8a37de143d98cb0beb5393055fcdc9d621765bb.tar.gz"
SHA1 "f8f91f0056bc46bba825bfff868136734f8585be"
URL "https://github.com/luxonis/XLink/archive/4f8cd1f9b2ab1b44e36c448a4b7d5d80255f5872.tar.gz"
SHA1 "fe7aaa8a61ddd7e9030c6c2720978e35a1449fba"
)

hunter_config(
Expand Down
3 changes: 3 additions & 0 deletions cmake/version.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ namespace build
constexpr static const char* COMMIT = "${BUILD_COMMIT}";
constexpr static const char* COMMIT_DATETIME = "${BUILD_COMMIT_DATETIME}";
constexpr static const char* BUILD_DATETIME = "${BUILD_DATETIME}";

constexpr static const char* DEVICE_VERSION = "${DEPTHAI_DEVICE_VERSION}";
constexpr static const char* BOOTLOADER_VERSION = "${DEPTHAI_BOOTLOADER_VERSION}";
} // namespace build
} // namespace dai
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ dai_add_example(feature_tracker FeatureTracker/feature_tracker.cpp ON)
dai_add_example(device_queue_event host_side/device_queue_event.cpp ON)
dai_add_example(opencv_support host_side/opencv_support.cpp ON)
dai_add_example(queue_add_callback host_side/queue_add_callback.cpp ON)
dai_add_example(device_information host_side/device_information.cpp ON)

# ImageManip
dai_add_example(image_manip ImageManip/image_manip_example.cpp ON)
Expand Down Expand Up @@ -307,13 +308,15 @@ dai_add_example(script_nndata_example Script/script_nndata_example.cpp ON)
dai_add_example(script_json_communication Script/script_json_communication.cpp ON)
dai_add_example(script_change_pipeline_flow Script/script_change_pipeline_flow.cpp OFF)
target_compile_definitions(script_change_pipeline_flow PRIVATE BLOB_PATH="${mobilenet_5shaves_blob}")
dai_add_example(script_get_device_info Script/script_get_device_info.cpp ON)

# SpatialDetection
dai_add_example(spatial_location_calculator SpatialDetection/spatial_location_calculator.cpp ON)
dai_add_example(spatial_mobilenet_mono SpatialDetection/spatial_mobilenet_mono.cpp ON)
dai_add_example(spatial_mobilenet SpatialDetection/spatial_mobilenet.cpp ON)
dai_add_example(spatial_tiny_yolo_v3 SpatialDetection/spatial_tiny_yolo.cpp ON)
dai_add_example(spatial_tiny_yolo_v4 SpatialDetection/spatial_tiny_yolo.cpp ON)
dai_add_example(spatial_calculator_multi_roi SpatialDetection/spatial_calculator_multi_roi.cpp ON)

target_compile_definitions(spatial_mobilenet_mono PRIVATE BLOB_PATH="${mobilenet_blob}")
target_compile_definitions(spatial_mobilenet PRIVATE BLOB_PATH="${mobilenet_blob}")
Expand Down
38 changes: 38 additions & 0 deletions examples/Script/script_get_device_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>

// Includes common necessary includes for development using depthai library
#include "depthai/depthai.hpp"

int main() {
using namespace std;

// Start defining a pipeline
dai::Pipeline pipeline;

// Script node
auto script = pipeline.create<dai::node::Script>();
script->setScript(R"(
import json
data = json.dumps({
'deviceId': __device_id__,
'fwVersion': __version__
}).encode('utf-8')
b = Buffer(len(data))
b.setData(data)
node.io['info'].send(b)
)");

// XLinkOut
auto xout = pipeline.create<dai::node::XLinkOut>();
xout->setStreamName("info");
script->outputs["info"].link(xout->input);

// Connect to device with pipeline
dai::Device device(pipeline);
auto msg = device.getOutputQueue("info")->get<dai::Buffer>();
auto data = nlohmann::json::parse(msg->getData());
std::cout << data.dump(4) << std::endl;

return 0;
}
2 changes: 1 addition & 1 deletion examples/Script/script_get_ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main() {
ip = get_ip_address('re0') # '192.168.0.110'
node.warn(f'IP of the device: {ip}')
node.io['end'].send(Buffer())
node.io['end'].send(Buffer(32))
)");

// XLinkOut
Expand Down
2 changes: 1 addition & 1 deletion examples/Script/script_http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main() {
data1 = r1.read()
node.warn(f'Public IP: {data1}')
node.io['end'].send(Buffer())
node.io['end'].send(Buffer(32))
)");

// XLinkOut
Expand Down
110 changes: 110 additions & 0 deletions examples/SpatialDetection/spatial_calculator_multi_roi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include <iostream>

#include "utility.hpp"

// Includes common necessary includes for development using depthai library
#include "depthai/depthai.hpp"

static constexpr float stepSize = 0.05f;

static std::atomic<bool> newConfig{false};

int main() {
using namespace std;

// Create pipeline
dai::Pipeline pipeline;

// Define sources and outputs
auto monoLeft = pipeline.create<dai::node::MonoCamera>();
auto monoRight = pipeline.create<dai::node::MonoCamera>();
auto stereo = pipeline.create<dai::node::StereoDepth>();
auto spatialLocationCalculator = pipeline.create<dai::node::SpatialLocationCalculator>();

auto xoutDepth = pipeline.create<dai::node::XLinkOut>();
auto xoutSpatialData = pipeline.create<dai::node::XLinkOut>();
auto xinSpatialCalcConfig = pipeline.create<dai::node::XLinkIn>();

xoutDepth->setStreamName("depth");
xoutSpatialData->setStreamName("spatialData");
xinSpatialCalcConfig->setStreamName("spatialCalcConfig");

// Properties
monoLeft->setResolution(dai::MonoCameraProperties::SensorResolution::THE_400_P);
monoLeft->setBoardSocket(dai::CameraBoardSocket::LEFT);
monoRight->setResolution(dai::MonoCameraProperties::SensorResolution::THE_400_P);
monoRight->setBoardSocket(dai::CameraBoardSocket::RIGHT);

stereo->setDefaultProfilePreset(dai::node::StereoDepth::PresetMode::HIGH_DENSITY);
stereo->setLeftRightCheck(true);
stereo->setExtendedDisparity(true);
spatialLocationCalculator->inputConfig.setWaitForMessage(false);

// Create 10 ROIs
for(int i = 0; i < 10; i++) {
dai::SpatialLocationCalculatorConfigData config;
config.depthThresholds.lowerThreshold = 200;
config.depthThresholds.upperThreshold = 10000;
config.roi = dai::Rect(dai::Point2f(i*0.1, 0.45), dai::Point2f((i+1)*0.1, 0.55));
spatialLocationCalculator->initialConfig.addROI(config);
}

// Linking
monoLeft->out.link(stereo->left);
monoRight->out.link(stereo->right);

spatialLocationCalculator->passthroughDepth.link(xoutDepth->input);
stereo->depth.link(spatialLocationCalculator->inputDepth);

spatialLocationCalculator->out.link(xoutSpatialData->input);
xinSpatialCalcConfig->out.link(spatialLocationCalculator->inputConfig);

// Connect to device and start pipeline
dai::Device device(pipeline);
device.setIrLaserDotProjectorBrightness(1000);

// Output queue will be used to get the depth frames from the outputs defined above
auto depthQueue = device.getOutputQueue("depth", 4, false);
auto spatialCalcQueue = device.getOutputQueue("spatialData", 4, false);
auto color = cv::Scalar(0, 200, 40);
auto fontType = cv::FONT_HERSHEY_TRIPLEX;

while(true) {
auto inDepth = depthQueue->get<dai::ImgFrame>();

cv::Mat depthFrame = inDepth->getFrame(); // depthFrame values are in millimeters

cv::Mat depthFrameColor;
cv::normalize(depthFrame, depthFrameColor, 255, 0, cv::NORM_INF, CV_8UC1);
cv::equalizeHist(depthFrameColor, depthFrameColor);
cv::applyColorMap(depthFrameColor, depthFrameColor, cv::COLORMAP_HOT);

auto spatialData = spatialCalcQueue->get<dai::SpatialLocationCalculatorData>()->getSpatialLocations();
for(auto depthData : spatialData) {
auto roi = depthData.config.roi;
roi = roi.denormalize(depthFrameColor.cols, depthFrameColor.rows);

auto xmin = static_cast<int>(roi.topLeft().x);
auto ymin = static_cast<int>(roi.topLeft().y);
auto xmax = static_cast<int>(roi.bottomRight().x);
auto ymax = static_cast<int>(roi.bottomRight().y);

auto coords = depthData.spatialCoordinates;
auto distance = std::sqrt(coords.x * coords.x + coords.y * coords.y + coords.z * coords.z);

cv::rectangle(depthFrameColor, cv::Rect(cv::Point(xmin, ymin), cv::Point(xmax, ymax)), color);
std::stringstream depthDistance;
depthDistance.precision(2);
depthDistance << fixed << static_cast<float>(distance/1000.0f) << "m";
cv::putText(depthFrameColor, depthDistance.str(), cv::Point(xmin + 10, ymin + 20), fontType, 0.5, color);
}
// Show the frame
cv::imshow("depth", depthFrameColor);

if(cv::waitKey(1) == 'q') {
break;
}

}
return 0;
}
Loading

0 comments on commit 907b8c0

Please sign in to comment.