Skip to content

Commit

Permalink
Merge branch 'release_2.15.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed Mar 16, 2022
2 parents 32e8e29 + daa12d0 commit b6e5f3b
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ jobs:
body: |
## Features
## Bugs
## Bug fixes
## Misc
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if(WIN32)
endif()

# Create depthai project
project(depthai VERSION "2.15.0" LANGUAGES CXX C)
project(depthai VERSION "2.15.1" LANGUAGES CXX C)
get_directory_property(has_parent PARENT_DIRECTORY)
if(has_parent)
set(DEPTHAI_VERSION ${PROJECT_VERSION} PARENT_SCOPE)
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 "fbbd61aaa70e094d40800e8e6cbb23548ecc24af")
set(DEPTHAI_DEVICE_SIDE_COMMIT "2bebad51c15c2e8961899a29b93b93f2409d8464")

# "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/6210f8da430b8dec0257cda93110c57657ce2d15.tar.gz"
SHA1 "58885ff0609ed5291039e512361bf7161b69910e"
URL "https://github.com/luxonis/XLink/archive/b7d8e6009ceb5b2278212e3f2a57f5f76e8df5d9.tar.gz"
SHA1 "5c5ebed8ae8ee8e289003ec6408c802d66df2fc3"
)

hunter_config(
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ dai_add_example(depth_crop_control StereoDepth/depth_crop_control.cpp ON)
dai_add_example(depth_preview StereoDepth/depth_preview.cpp ON)
dai_add_example(depth_post_processing StereoDepth/depth_post_processing.cpp ON)
dai_add_example(rgb_depth_aligned StereoDepth/rgb_depth_aligned.cpp ON)
dai_add_example(rgb_depth_confidence_aligned StereoDepth/rgb_depth_confidence_aligned.cpp ON)
dai_add_example(stereo_depth_video StereoDepth/stereo_depth_video.cpp ON)

# SystemLogger
Expand Down
3 changes: 2 additions & 1 deletion examples/Script/script_json_communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int main() {
auto jsonData = device.getOutputQueue("out")->get<dai::Buffer>();
auto changedDict = nlohmann::json::parse(jsonData->getData());
cout << "changedDict: " << changedDict << "\n";

const nlohmann::json expectedDict{{"one", 2}, {"foo", "baz"}};
if(expectedDict != changedDict) return 1;
return 0;
}
170 changes: 170 additions & 0 deletions examples/StereoDepth/rgb_depth_confidence_aligned.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#include <cstdio>
#include <iostream>

#include "utility.hpp"

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

// Optional. If set (true), the ColorCamera is downscaled from 1080p to 720p.
// Otherwise (false), the aligned depth is automatically upscaled to 1080p
static std::atomic<bool> downscaleColor{true};
static constexpr int fps = 30;
// The disparity is computed at this resolution, then upscaled to RGB resolution
static constexpr auto monoRes = dai::MonoCameraProperties::SensorResolution::THE_720_P;

static float rgbWeight = 0.3f;
static float depthWeight = 0.3f;
static float confWeight = 0.3f;

static float rgbWeightNorm = 0.3f;
static float depthWeightNorm = 0.3f;
static float confWeightNorm = 0.3f;

static void updateBlendWeights(int percentRgb, void* weight) {
*((float*)weight) = float(percentRgb) / 100.f;
}

int main() {
using namespace std;

// Create pipeline
dai::Pipeline pipeline;
std::vector<std::string> queueNames;

// Define sources and outputs
auto camRgb = pipeline.create<dai::node::ColorCamera>();
auto left = pipeline.create<dai::node::MonoCamera>();
auto right = pipeline.create<dai::node::MonoCamera>();
auto stereo = pipeline.create<dai::node::StereoDepth>();

auto rgbOut = pipeline.create<dai::node::XLinkOut>();
auto depthOut = pipeline.create<dai::node::XLinkOut>();
auto confOut = pipeline.create<dai::node::XLinkOut>();

rgbOut->setStreamName("rgb");
queueNames.push_back("rgb");
depthOut->setStreamName("depth");
queueNames.push_back("depth");
confOut->setStreamName("conf");
queueNames.push_back("conf");

// Properties
camRgb->setBoardSocket(dai::CameraBoardSocket::RGB);
camRgb->setResolution(dai::ColorCameraProperties::SensorResolution::THE_1080_P);
camRgb->setFps(fps);
if(downscaleColor) camRgb->setIspScale(2, 3);
// For now, RGB needs fixed focus to properly align with depth.
// This value was used during calibration
camRgb->initialControl.setManualFocus(135);

left->setResolution(monoRes);
left->setBoardSocket(dai::CameraBoardSocket::LEFT);
left->setFps(fps);
right->setResolution(monoRes);
right->setBoardSocket(dai::CameraBoardSocket::RIGHT);
right->setFps(fps);

stereo->setDefaultProfilePreset(dai::node::StereoDepth::PresetMode::HIGH_DENSITY);
// LR-check is required for depth alignment
stereo->setLeftRightCheck(true);
stereo->setDepthAlign(dai::CameraBoardSocket::RGB);

// Linking
camRgb->isp.link(rgbOut->input);
left->out.link(stereo->left);
right->out.link(stereo->right);
stereo->disparity.link(depthOut->input);
stereo->confidenceMap.link(confOut->input);

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

// Sets queues size and behavior
for(const auto& name : queueNames) {
device.getOutputQueue(name, 4, false);
}

std::unordered_map<std::string, cv::Mat> frame;

auto rgbWindowName = "rgb";
auto depthWindowName = "depth";
auto confWindowName = "conf";
auto blendedWindowName = "rgb-depth-confidence";
cv::namedWindow(rgbWindowName);
cv::namedWindow(depthWindowName);
cv::namedWindow(confWindowName);
cv::namedWindow(blendedWindowName);
int defRgbWeightValue = (int)(rgbWeight * 100);
int defDepthWeightValue = (int)(rgbWeight * 100);
int defConfWeightValue = (int)(rgbWeight * 100);
cv::createTrackbar("RGB Weight %", blendedWindowName, &defRgbWeightValue, 100, updateBlendWeights, &rgbWeight);
cv::createTrackbar("Depth Weight %", blendedWindowName, &defDepthWeightValue, 100, updateBlendWeights, &depthWeight);
cv::createTrackbar("Confidence Weight %", blendedWindowName, &defConfWeightValue, 100, updateBlendWeights, &confWeight);

while(true) {
std::unordered_map<std::string, std::shared_ptr<dai::ImgFrame>> latestPacket;

auto queueEvents = device.getQueueEvents(queueNames);
for(const auto& name : queueEvents) {
auto packets = device.getOutputQueue(name)->tryGetAll<dai::ImgFrame>();
auto count = packets.size();
if(count > 0) {
latestPacket[name] = packets[count - 1];
}
}

for(const auto& name : queueNames) {
if(latestPacket.find(name) != latestPacket.end()) {
if(name == depthWindowName) {
frame[name] = latestPacket[name]->getFrame();
auto maxDisparity = stereo->initialConfig.getMaxDisparity();
// Optional, extend range 0..95 -> 0..255, for a better visualisation
if(1) frame[name].convertTo(frame[name], CV_8UC1, 255. / maxDisparity);
// Optional, apply false colorization
if(1) cv::applyColorMap(frame[name], frame[name], cv::COLORMAP_HOT);
} else {
frame[name] = latestPacket[name]->getCvFrame();
}

cv::imshow(name, frame[name]);
}
}

// Blend when all three frames received
if(frame.find(rgbWindowName) != frame.end() && frame.find(depthWindowName) != frame.end() && frame.find(confWindowName) != frame.end()) {
// Need to have all three frames in BGR format before blending
if(frame[depthWindowName].channels() < 3) {
cv::cvtColor(frame[depthWindowName], frame[depthWindowName], cv::COLOR_GRAY2BGR);
}
if(frame[confWindowName].channels() < 3) {
cv::cvtColor(frame[confWindowName], frame[confWindowName], cv::COLOR_GRAY2BGR);
}

float sumWeight = rgbWeight + depthWeight + confWeight;
// Normalize the weights so their sum to be <= 1.0
if (sumWeight <= 1.0) {
rgbWeightNorm = rgbWeight;
depthWeightNorm = depthWeight;
confWeightNorm = confWeight;
}
else {
rgbWeightNorm = rgbWeight / sumWeight;
depthWeightNorm = depthWeight / sumWeight;
confWeightNorm = confWeight / sumWeight;
}

cv::Mat blended1, blended2;
cv::addWeighted(frame[rgbWindowName], rgbWeightNorm, frame[depthWindowName], depthWeightNorm, 0, blended1);
cv::addWeighted(blended1, rgbWeightNorm + depthWeightNorm, frame[confWindowName], confWeightNorm, 0, blended2);
cv::imshow(blendedWindowName, blended2);
frame.clear();
}

int key = cv::waitKey(1);
if(key == 'q' || key == 'Q') {
return 0;
}
}
return 0;
}
2 changes: 1 addition & 1 deletion src/device/CallbackHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CallbackHandler::CallbackHandler(std::shared_ptr<XLinkConnection> conn,
const auto data = StreamMessageParser::parseMessage(&packet);

// CALLBACK
auto toSend = callback(data);
auto toSend = callback(std::move(data));

auto serialized = StreamMessageParser::serializeMessage(toSend);

Expand Down
8 changes: 4 additions & 4 deletions src/device/DataQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ int DataOutputQueue::addCallback(std::function<void(std::string, std::shared_ptr
// Get unique id
int id = uniqueCallbackId++;

// assign callback
callbacks[id] = callback;
// move assign callback
callbacks[id] = std::move(callback);

// return id assigned to the callback
return id;
}

int DataOutputQueue::addCallback(std::function<void(std::shared_ptr<ADatatype>)> callback) {
// Create a wrapper
return addCallback([callback](std::string, std::shared_ptr<ADatatype> message) { callback(message); });
return addCallback([callback = std::move(callback)](std::string, std::shared_ptr<ADatatype> message) { callback(std::move(message)); });
}

int DataOutputQueue::addCallback(std::function<void()> callback) {
// Create a wrapper
return addCallback([callback](std::string, std::shared_ptr<ADatatype>) { callback(); });
return addCallback([callback = std::move(callback)](std::string, std::shared_ptr<ADatatype>) { callback(); });
}

bool DataOutputQueue::removeCallback(int callbackId) {
Expand Down
2 changes: 1 addition & 1 deletion src/device/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ bool Device::startPipelineImpl(const Pipeline& pipeline) {
}

// Add to the end of event queue
eventQueue.push_back(queueName);
eventQueue.push_back(std::move(queueName));
}

// notify the rest
Expand Down
1 change: 1 addition & 0 deletions src/pipeline/node/StereoDepth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ StereoDepth::StereoDepth(const std::shared_ptr<PipelineImpl>& par, int64_t nodeI
&confidenceMap});

setDefaultProfilePreset(presetMode);
setFocalLengthFromCalibration(true);
}

StereoDepth::Properties& StereoDepth::getProperties() {
Expand Down
7 changes: 4 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ function(dai_add_test test_name test_src)
set_tests_properties(${test_name} PROPERTIES ENVIRONMENT "UBSAN_OPTIONS=halt_on_error=1;DEPTHAI_PROTOCOL=usb" LABELS usb)

# Check if MSVC and add a conforming preprocessor test (serialization macros)
if (MSVC)
if(MSVC)
# Create test executable with MSVC conforming preprocessor
add_executable(${test_name}_conforming ${test_src})
add_default_flags(${test_name}_conforming LEAN)

# Link to core and Catch2 testing framework
target_link_libraries(${test_name}_conforming PRIVATE depthai-core Catch2::Catch2)

if(MSVC_VERSION LESS 1925)
target_compile_options(${test_name}_conforming INTERFACE "/experimental:preprocessor")
target_compile_options(${test_name}_conforming PRIVATE "/experimental:preprocessor")
else()
target_compile_options(${test_name}_conforming INTERFACE "/Zc:preprocessor")
target_compile_options(${test_name}_conforming PRIVATE "/Zc:preprocessor")
endif()

# Add to list of tests
Expand Down

0 comments on commit b6e5f3b

Please sign in to comment.