Skip to content

Commit

Permalink
Merge pull request #790 from luxonis/develop
Browse files Browse the repository at this point in the history
Release v2.21.0
  • Loading branch information
SzabolcsGergely committed Apr 1, 2023
2 parents 5ead66c + a0def1f commit f8c459e
Show file tree
Hide file tree
Showing 59 changed files with 570 additions and 320 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-11, windows-latest, ubuntu-latest]
os: [macos-latest, windows-latest, ubuntu-latest]
cmake: ['3.10.x', ''] # Older version (Ubuntu 18.04) and newest
exclude:
- os: windows-latest
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
cmake-version: ${{ matrix.cmake }}

- name: Install dependencies
if: matrix.os == 'macos-11'
if: matrix.os == 'macos-latest'
run: |
brew install opencv
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-11, windows-latest, ubuntu-latest]
os: [macos-latest, windows-latest, ubuntu-latest]
build-type: [Debug, Release]
shared: [true, false]
platform: [x64]
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
submodules: 'recursive'

- name: Install dependencies
if: matrix.os == 'macos-11'
if: matrix.os == 'macos-latest'
run: |
brew install opencv
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if(WIN32)
endif()

# Create depthai project
project(depthai VERSION "2.20.2" LANGUAGES CXX C)
project(depthai VERSION "2.21.0" LANGUAGES CXX C)
get_directory_property(has_parent PARENT_DIRECTORY)
if(has_parent)
set(DEPTHAI_VERSION ${PROJECT_VERSION} PARENT_SCOPE)
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ cmake -S. -Bbuild -D'BUILD_SHARED_LIBS=ON'
cmake --build build
```


### Android

Android is supported to some extent but not actively pursued nor tested. PRs with any improvements are welcome.

Steps:

- Install Android NDK (for example via Android Studio).
- Set the NDK path:
```
export ANDROID_HOME=$HOME/.local/lib/Android
export PATH=$PATH:$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools
export NDK=$ANDROID_HOME/ndk/23.1.7779620/ # Check version
```
- Ensure a recent version of cmake (apt version is outdated, install snap install cmake --classic)
- Run cmake, set your ABI and Platform as needed:

```
cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-25
cmake --build build
```


## Running examples

To build the examples configure with following option added
Expand Down
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 "8c3d6ac1c77b0bf7f9ea6fd4d962af37663d2fbd")
set(DEPTHAI_DEVICE_SIDE_COMMIT "57ca2c171f6ef53cb83fbbc3aabfe512c67796ce")

# "version if applicable"
set(DEPTHAI_DEVICE_SIDE_VERSION "")
8 changes: 4 additions & 4 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/1ef2f960eec66540891434c9a3341c11e66e4360.tar.gz"
SHA1 "23641bb9ae698d0e016abcce349094a38577838b"
URL "https://github.com/luxonis/XLink/archive/b7c3aca2ba8b9d598be886a8076a875b50f5184f.tar.gz"
SHA1 "6c19757c6fe6871a9f40688871edbfc6f1e939ee"
)

hunter_config(
Expand Down Expand Up @@ -100,8 +100,8 @@ hunter_config(
hunter_config(
Catch2
VERSION "2.13.7"
URL "https://github.com/catchorg/Catch2/archive/refs/tags/v2.13.7.tar.gz"
SHA1 "fa8f14ccf852413d3c6d3999145ada934d37d773"
URL "https://github.com/catchorg/Catch2/archive/refs/tags/v3.2.1.tar.gz"
SHA1 "acfba7f71cbbbbf60bc1bc4c0e3efca4a9c70df7"
)

# ZLib - Luxonis fix for alias on imported target for old CMake versions
Expand Down
7 changes: 7 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ function(dai_add_example example_name example_src enable_test)
add_executable(${example_name} ${example_src})
add_default_flags(${example_name} LEAN)
target_link_libraries(${example_name} PRIVATE utility depthai::opencv ${OpenCV_LIBS} Threads::Threads)
# Set compiler features (c++14), and disables extensions (g++14)
set_property(TARGET ${example_name} PROPERTY CXX_STANDARD 14)
set_property(TARGET ${example_name} PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET ${example_name} PROPERTY CXX_EXTENSIONS OFF)

# Add sanitizers for example
if(COMMAND add_sanitizers)
Expand Down Expand Up @@ -359,3 +363,6 @@ dai_add_example(apriltag_rgb AprilTag/apriltag_rgb.cpp ON)
# DetectionParser
dai_add_example(detection_parser NeuralNetwork/detection_parser.cpp ON)
target_compile_definitions(detection_parser PRIVATE BLOB_PATH="${mobilenet_blob}")

# DetectionParser
dai_add_example(crash_report CrashReport/crash_report.cpp OFF)
41 changes: 41 additions & 0 deletions examples/CrashReport/crash_report.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <fstream>
#include <iostream>

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

static bool fileExists(dai::Path path) {
std::ifstream file(path);
return file.is_open();
}

int main() {
using namespace std;

// Connect to device and start pipeline
dai::Device device;
if(device.hasCrashDump()) {
auto crashDump = device.getCrashDump();
std::string commitHash = crashDump.depthaiCommitHash;
std::string deviceId = crashDump.deviceId;

auto json = crashDump.serializeToJson();

for(int i = 0;; i++) {
dai::Path destPath = "crashDump_" + to_string(i) + "_" + deviceId + "_" + commitHash + ".json";
if(fileExists(destPath)) continue;

std::ofstream ob(destPath);
ob << std::setw(4) << json << std::endl;

std::cout << "Crash dump found on your device!" << std::endl;
std::cout << "Saved to " << destPath.string() << std::endl;
std::cout << "Please report to developers!" << std::endl;
break;
}
} else {
std::cout << "There was no crash dump found on your device!" << std::endl;
}

return 0;
}
4 changes: 1 addition & 3 deletions examples/FeatureTracker/feature_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class FeatureTrackerDrawer {
}
}

FeatureTrackerDrawer(std::string trackbarName, std::string windowName) {
this->trackbarName = trackbarName;
this->windowName = windowName;
FeatureTrackerDrawer(std::string trackbarName, std::string windowName) : trackbarName(trackbarName), windowName(windowName) {
cv::namedWindow(windowName.c_str());
cv::createTrackbar(trackbarName.c_str(), windowName.c_str(), &trackedFeaturesPathLength, maxTrackedFeaturesPathLength, nullptr);
}
Expand Down
82 changes: 24 additions & 58 deletions examples/IMU/imu_firmware_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ int main() {
using namespace std;
using namespace std::chrono;

dai::Device device;

auto imuType = device.getConnectedIMU();
auto imuFirmwareVersion = device.getIMUFirmwareVersion();
auto embeddedIMUFirmwareVersion = device.getEmbeddedIMUFirmwareVersion();
std::cout << "IMU type: " << imuType << " firmware version: " << imuFirmwareVersion
<< " embedded firmware version: " << embeddedIMUFirmwareVersion << std::endl;

std::cout << "Warning! Flashing IMU firmware can potentially soft brick your device and should be done with caution." << std::endl;
std::cout << "Do not unplug your device while the IMU firmware is flashing." << std::endl;
std::cout << "Type 'y' and press enter to proceed, otherwise exits: ";
Expand All @@ -20,68 +28,26 @@ int main() {
return -1;
}

// Create pipeline
dai::Pipeline pipeline;

// Define sources and outputs
auto imu = pipeline.create<dai::node::IMU>();
auto xlinkOut = pipeline.create<dai::node::XLinkOut>();

xlinkOut->setStreamName("imu");

// enable ACCELEROMETER_RAW at 500 hz rate
imu->enableIMUSensor(dai::IMUSensor::ACCELEROMETER_RAW, 500);
// enable GYROSCOPE_RAW at 400 hz rate
imu->enableIMUSensor(dai::IMUSensor::GYROSCOPE_RAW, 400);
// it's recommended to set both setBatchReportThreshold and setMaxBatchReports to 20 when integrating in a pipeline with a lot of input/output connections
// above this threshold packets will be sent in batch of X, if the host is not blocked and USB bandwidth is available
imu->setBatchReportThreshold(1);
// maximum number of IMU packets in a batch, if it's reached device will block sending until host can receive it
// if lower or equal to batchReportThreshold then the sending is always blocking on device
// useful to reduce device's CPU load and number of lost packets, if CPU load is high on device side due to multiple nodes
imu->setMaxBatchReports(10);

// Link plugins IMU -> XLINK
imu->out.link(xlinkOut->input);

imu->enableFirmwareUpdate(true);

// Pipeline is defined, now we can connect to the device
dai::Device d(pipeline);

bool firstTs = false;

auto imuQueue = d.getOutputQueue("imu", 50, false);
auto baseTs = std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration>();
auto started = device.startIMUFirmwareUpdate();
if(!started) {
std::cout << "Couldn't start IMU firmware update" << std::endl;
return 1;
}

while(true) {
auto imuData = imuQueue->get<dai::IMUData>();

auto imuPackets = imuData->packets;
for(auto& imuPacket : imuPackets) {
auto& acceleroValues = imuPacket.acceleroMeter;
auto& gyroValues = imuPacket.gyroscope;

auto acceleroTs1 = acceleroValues.getTimestampDevice();
auto gyroTs1 = gyroValues.getTimestampDevice();
if(!firstTs) {
baseTs = std::min(acceleroTs1, gyroTs1);
firstTs = true;
bool fwUpdateFinished;
float percentage;
std::tie(fwUpdateFinished, percentage) = device.getIMUFirmwareUpdateStatus();
std::cout << "IMU FW update status: " << std::setprecision(1) << percentage << std::endl;
if(fwUpdateFinished) {
if(percentage == 100) {
std::cout << "Firmware update successful!" << std::endl;
} else {
std::cout << "Firmware update failed!" << std::endl;
}

auto acceleroTs = acceleroTs1 - baseTs;
auto gyroTs = gyroTs1 - baseTs;

printf("Accelerometer timestamp: %ld ms\n", static_cast<long>(duration_cast<milliseconds>(acceleroTs).count()));
printf("Accelerometer [m/s^2]: x: %.3f y: %.3f z: %.3f \n", acceleroValues.x, acceleroValues.y, acceleroValues.z);
printf("Gyroscope timestamp: %ld ms\n", static_cast<long>(duration_cast<milliseconds>(gyroTs).count()));
printf("Gyroscope [rad/s]: x: %.3f y: %.3f z: %.3f \n", gyroValues.x, gyroValues.y, gyroValues.z);
}

int key = cv::waitKey(1);
if(key == 'q') {
return 0;
break;
}
std::this_thread::sleep_for(1s);
}

return 0;
Expand Down
28 changes: 28 additions & 0 deletions examples/SpatialDetection/spatial_location_calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ int main() {
dai::SpatialLocationCalculatorConfigData config;
config.depthThresholds.lowerThreshold = 100;
config.depthThresholds.upperThreshold = 10000;
auto calculationAlgorithm = dai::SpatialLocationCalculatorAlgorithm::MEDIAN;
config.calculationAlgorithm = calculationAlgorithm;
config.roi = dai::Rect(topLeft, bottomRight);

spatialDataCalculator->inputConfig.setWaitForMessage(false);
Expand Down Expand Up @@ -144,12 +146,38 @@ int main() {
newConfig = true;
}
break;
case '1':
calculationAlgorithm = dai::SpatialLocationCalculatorAlgorithm::MEAN;
newConfig = true;
std::cout << "Switching calculation algorithm to MEAN!" << std::endl;
break;
case '2':
calculationAlgorithm = dai::SpatialLocationCalculatorAlgorithm::MIN;
newConfig = true;
std::cout << "Switching calculation algorithm to MIN!" << std::endl;
break;
case '3':
calculationAlgorithm = dai::SpatialLocationCalculatorAlgorithm::MAX;
newConfig = true;
std::cout << "Switching calculation algorithm to MAX!" << std::endl;
break;
case '4':
calculationAlgorithm = dai::SpatialLocationCalculatorAlgorithm::MODE;
newConfig = true;
std::cout << "Switching calculation algorithm to MODE!" << std::endl;
break;
case '5':
calculationAlgorithm = dai::SpatialLocationCalculatorAlgorithm::MEDIAN;
newConfig = true;
std::cout << "Switching calculation algorithm to MEDIAN!" << std::endl;
break;
default:
break;
}

if(newConfig) {
config.roi = dai::Rect(topLeft, bottomRight);
config.calculationAlgorithm = calculationAlgorithm;
dai::SpatialLocationCalculatorConfig cfg;
cfg.addROI(config);
spatialCalcConfigInQueue->send(cfg);
Expand Down
1 change: 0 additions & 1 deletion examples/StereoDepth/stereo_depth_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ int main() {
cv::imshow("right", right->getFrame());

if(withDepth) {
// Note: in some configurations (if depth is enabled), disparity may output garbage data
auto disparity = dispQueue->get<dai::ImgFrame>();
cv::Mat disp(disparity->getCvFrame());
disp.convertTo(disp, CV_8UC1, disparityMultiplier); // Extend disparity range
Expand Down
10 changes: 9 additions & 1 deletion include/depthai/device/DataQueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class DataOutputQueue {

/**
* Check whether queue is closed
*
* @warning This function is thread-unsafe and may return outdated incorrect values. It is
* only meant for use in simple single-threaded code. Well written code should handle
* exceptions when calling any DepthAI apis to handle hardware events and multithreaded use.
*/
bool isClosed() const;

Expand Down Expand Up @@ -343,7 +347,7 @@ class DataInputQueue {
std::atomic<bool> running{true};
std::string exceptionMessage;
const std::string name;
std::size_t maxDataSize = device::XLINK_USB_BUFFER_MAX_SIZE;
std::atomic<std::size_t> maxDataSize{device::XLINK_USB_BUFFER_MAX_SIZE};

public:
DataInputQueue(const std::shared_ptr<XLinkConnection> conn,
Expand All @@ -355,6 +359,10 @@ class DataInputQueue {

/**
* Check whether queue is closed
*
* @warning This function is thread-unsafe and may return outdated incorrect values. It is
* only meant for use in simple single-threaded code. Well written code should handle
* exceptions when calling any DepthAI apis to handle hardware events and multithreaded use.
*/
bool isClosed() const;

Expand Down
Loading

0 comments on commit f8c459e

Please sign in to comment.