Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message groups #917

Merged
merged 49 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c9fb1d7
Implemented metadata serialization
asahtik Oct 5, 2023
88d1c6b
Implemented raw data serialization in MG
asahtik Oct 9, 2023
810647e
Merge branch 'develop' of github.com:luxonis/depthai-core into messag…
asahtik Oct 9, 2023
b5150b1
Implemented sync node
asahtik Oct 18, 2023
49a7c34
Fixed msggrp serialization
asahtik Oct 27, 2023
8a37a5a
Bump shared
asahtik Oct 27, 2023
0a66ca7
Simplified msggrp
asahtik Oct 28, 2023
09abc65
Merge resolution
asahtik Oct 30, 2023
d1a1d3b
Bump shared
asahtik Oct 30, 2023
d22bbb5
Fixed python bindings
asahtik Oct 30, 2023
92950cc
Bump shared
asahtik Oct 30, 2023
b65c24d
Implemented messagedemux
asahtik Nov 2, 2023
5c668f3
Added doc comments
asahtik Nov 2, 2023
ac76211
Merge branch 'develop' of github.com:luxonis/depthai-core into messag…
asahtik Nov 2, 2023
2142130
Bump shared
asahtik Nov 2, 2023
fc308cf
Bump firmware
asahtik Nov 2, 2023
a2f4092
Merge branch 'video_encoder_frame' of github.com:luxonis/depthai-core…
asahtik Nov 3, 2023
a8c2c0e
Removed unnecessary functions
asahtik Nov 3, 2023
7be4ef8
Redid messageGroups
asahtik Nov 4, 2023
2319297
Changed dynamic to static cast
asahtik Nov 6, 2023
0ebded2
Added option to only demux successful syncs
asahtik Nov 6, 2023
5709112
Added ability to set success on msggrp
asahtik Nov 6, 2023
a1e6bf1
Clangformat
asahtik Nov 6, 2023
4b943ea
Merge branch 'develop' of github.com:luxonis/depthai-core into messag…
asahtik Nov 8, 2023
6e8e67d
Fix warning
asahtik Nov 8, 2023
94c2acf
Bump shared
asahtik Nov 13, 2023
725a57a
Added tests for encframe
asahtik Nov 13, 2023
57e4c10
Changed the way sync works + added test
asahtik Nov 14, 2023
daba851
Changed the way sync is configured
asahtik Nov 15, 2023
bb8ebd4
Clangformat
asahtik Nov 15, 2023
190fdc0
Added examples + bump fw
asahtik Nov 15, 2023
94f2085
Added example, removed numPools from Sync
asahtik Nov 17, 2023
8a5175b
Minor modification to example
asahtik Nov 17, 2023
f91a1bd
Bump fw
asahtik Nov 17, 2023
feeb2ee
Throw error when indexing non-existing message, changed example to us…
asahtik Nov 20, 2023
2928de7
Improved example
asahtik Nov 20, 2023
5bd2e4c
Clangformat
asahtik Nov 20, 2023
3f50eaf
Merge branch 'develop' of github.com:luxonis/depthai-core into messag…
asahtik Nov 20, 2023
e4bbd6e
Changed syncThreshold setter to use chrono duration
asahtik Nov 20, 2023
af2ec17
Bump shared
asahtik Nov 22, 2023
eb1f606
Bump fw
asahtik Nov 23, 2023
119e3a5
Clangformat
asahtik Nov 23, 2023
16ebb17
Bump fw
asahtik Nov 23, 2023
0c480a1
Bump fw
asahtik Nov 23, 2023
98360b5
Merge branch 'develop' of github.com:luxonis/depthai-core into messag…
asahtik Nov 24, 2023
fad0a31
Rename connectivity enum
asahtik Nov 24, 2023
5229636
Minor encframe test fixes
asahtik Nov 27, 2023
74384c5
Bump fw
asahtik Nov 27, 2023
a5b6cbb
TODO fix windows test
asahtik Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ add_library(${TARGET_CORE_NAME}
src/pipeline/node/ColorCamera.cpp
src/pipeline/node/Camera.cpp
src/pipeline/node/ToF.cpp
src/pipeline/node/MessageDemux.cpp
src/pipeline/node/MonoCamera.cpp
src/pipeline/node/StereoDepth.cpp
src/pipeline/node/Sync.cpp
src/pipeline/node/NeuralNetwork.cpp
src/pipeline/node/ImageManip.cpp
src/pipeline/node/Warp.cpp
Expand Down Expand Up @@ -248,6 +250,7 @@ add_library(${TARGET_CORE_NAME}
src/pipeline/datatype/TrackedFeatures.cpp
src/pipeline/datatype/FeatureTrackerConfig.cpp
src/pipeline/datatype/ToFConfig.cpp
src/pipeline/datatype/MessageGroup.cpp
src/utility/H26xParsers.cpp
src/utility/Initialization.cpp
src/utility/Resources.cpp
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 "cae51725e78d8128ee7324c13f74648bcc59addc")
set(DEPTHAI_DEVICE_SIDE_COMMIT "36ce766b29927e2b6bd8873d4e3799ccca3cb821")

# "version if applicable"
set(DEPTHAI_DEVICE_SIDE_VERSION "")
6 changes: 3 additions & 3 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ hunter_config(
# Specific Catch2 version
hunter_config(
Catch2
VERSION "2.13.7"
URL "https://github.com/catchorg/Catch2/archive/refs/tags/v3.2.1.tar.gz"
SHA1 "acfba7f71cbbbbf60bc1bc4c0e3efca4a9c70df7"
VERSION "3.4.0"
URL "https://github.com/catchorg/Catch2/archive/refs/tags/v3.4.0.tar.gz"
SHA1 "4c308576c856a43dc88949a8f64ef90ebf94ae1b"
)

# ZLib - Luxonis fix for alias on imported target for old CMake versions
Expand Down
5 changes: 5 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,8 @@ target_compile_definitions(detection_parser PRIVATE BLOB_PATH="${mobilenet_blob}

# DetectionParser
dai_add_example(crash_report CrashReport/crash_report.cpp OFF)

# Sync
dai_add_example(sync_scripts Sync/sync_scripts.cpp ON)
dai_add_example(demux_message_group Sync/demux_message_group.cpp ON)
dai_add_example(depth_video_synced Sync/depth_video_synced.cpp ON)
63 changes: 63 additions & 0 deletions examples/Sync/demux_message_group.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <chrono>
#include <iostream>

#include "depthai/depthai.hpp"

int main() {
dai::Pipeline pipeline;

auto script1 = pipeline.create<dai::node::Script>();
script1->setScript(
R"SCRPT(
from time import sleep

while True:
sleep(1)
b = Buffer(512)
b.setData(bytes(4 * [i for i in range(0, 128)]))
b.setTimestamp(Clock.now())
node.io['out'].send(b)
)SCRPT");

auto script2 = pipeline.create<dai::node::Script>();
script2->setScript(
R"SCRPT(
from time import sleep

while True:
sleep(0.3)
b = Buffer(512)
b.setData(bytes(4 * [i for i in range(128, 256)]))
b.setTimestamp(Clock.now())
node.io['out'].send(b)
)SCRPT");

auto sync = pipeline.create<dai::node::Sync>();
sync->setSyncThreshold(std::chrono::milliseconds(100));

auto demux = pipeline.create<dai::node::MessageDemux>();

auto xout1 = pipeline.create<dai::node::XLinkOut>();
xout1->setStreamName("xout1");
auto xout2 = pipeline.create<dai::node::XLinkOut>();
xout2->setStreamName("xout2");

script1->outputs["out"].link(sync->inputs["s1"]);
script2->outputs["out"].link(sync->inputs["s2"]);
sync->out.link(demux->input);
demux->outputs["s1"].link(xout1->input);
demux->outputs["s2"].link(xout2->input);

dai::Device device(pipeline);
std::cout << "Start" << std::endl;
auto queue1 = device.getOutputQueue("xout1", 10, true);
auto queue2 = device.getOutputQueue("xout2", 10, true);
while(true) {
auto bufS1 = queue1->get<dai::Buffer>();
auto bufS2 = queue2->get<dai::Buffer>();
std::cout << "Buffer 1 timestamp: " << bufS1->getTimestamp().time_since_epoch().count() << std::endl;
std::cout << "Buffer 2 timestamp: " << bufS2->getTimestamp().time_since_epoch().count() << std::endl;
std::cout << "----------" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
}
68 changes: 68 additions & 0 deletions examples/Sync/depth_video_synced.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <iostream>

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

int main() {
// Create pipeline
dai::Pipeline pipeline;

// Define sources and outputs
auto monoLeft = pipeline.create<dai::node::MonoCamera>();
auto monoRight = pipeline.create<dai::node::MonoCamera>();
auto color = pipeline.create<dai::node::ColorCamera>();
auto stereo = pipeline.create<dai::node::StereoDepth>();
auto sync = pipeline.create<dai::node::Sync>();

auto xoutGrp = pipeline.create<dai::node::XLinkOut>();

// XLinkOut
xoutGrp->setStreamName("xout");

// Properties
monoLeft->setResolution(dai::MonoCameraProperties::SensorResolution::THE_400_P);
monoLeft->setCamera("left");
monoRight->setResolution(dai::MonoCameraProperties::SensorResolution::THE_400_P);
monoRight->setCamera("right");

stereo->setDefaultProfilePreset(dai::node::StereoDepth::PresetMode::HIGH_ACCURACY);

color->setCamera("color");

sync->setSyncThreshold(std::chrono::milliseconds(100));

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

stereo->disparity.link(sync->inputs["disparity"]);
color->video.link(sync->inputs["video"]);

sync->out.link(xoutGrp->input);

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

auto queue = device.getOutputQueue("xout", 10, true);

float disparityMultiplier = 255 / stereo->initialConfig.getMaxDisparity();

while(true) {
auto msgGrp = queue->get<dai::MessageGroup>();
for(auto& frm : *msgGrp) {
auto imgFrm = std::dynamic_pointer_cast<dai::ImgFrame>(frm.second);
cv::Mat img = imgFrm->getCvFrame();
if(frm.first == "disparity") {
img.convertTo(img, CV_8UC1, disparityMultiplier); // Extend disparity range
cv::applyColorMap(img, img, cv::COLORMAP_JET);
}
cv::imshow(frm.first, img);
}

int key = cv::waitKey(1);
if(key == 'q' || key == 'Q') {
return 0;
}
}
return 0;
}
56 changes: 56 additions & 0 deletions examples/Sync/sync_scripts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <chrono>
#include <iostream>

#include "depthai/depthai.hpp"

int main() {
dai::Pipeline pipeline;

auto script1 = pipeline.create<dai::node::Script>();
script1->setScript(
R"SCRPT(
from time import sleep

while True:
sleep(1)
b = Buffer(512)
b.setData(bytes(4 * [i for i in range(0, 128)]))
b.setTimestamp(Clock.now())
node.io['out'].send(b)
)SCRPT");

auto script2 = pipeline.create<dai::node::Script>();
script2->setScript(
R"SCRPT(
from time import sleep

while True:
sleep(0.3)
b = Buffer(512)
b.setData(bytes(4 * [i for i in range(128, 256)]))
b.setTimestamp(Clock.now())
node.io['out'].send(b)
)SCRPT");

auto sync = pipeline.create<dai::node::Sync>();
sync->setSyncThreshold(std::chrono::milliseconds(100));

auto xout = pipeline.create<dai::node::XLinkOut>();
xout->setStreamName("xout");

sync->out.link(xout->input);
script1->outputs["out"].link(sync->inputs["s1"]);
script2->outputs["out"].link(sync->inputs["s2"]);

dai::Device device(pipeline);
std::cout << "Start" << std::endl;
auto queue = device.getOutputQueue("xout", 10, true);
while(true) {
auto grp = queue->get<dai::MessageGroup>();
std::cout << "Buffer 1 timestamp: " << grp->get<dai::Buffer>("s1")->getTimestamp().time_since_epoch().count() << std::endl;
std::cout << "Buffer 2 timestamp: " << grp->get<dai::Buffer>("s2")->getTimestamp().time_since_epoch().count() << std::endl;
std::cout << "Time interval between messages: " << static_cast<double>(grp->getIntervalNs()) / 1e6 << "ms" << std::endl;
std::cout << "----------" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
}
6 changes: 3 additions & 3 deletions include/depthai/device/DeviceBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

// shared
#include "depthai-shared/common/ChipTemperature.hpp"
#include "depthai-shared/common/Connectivity.hpp"
#include "depthai-shared/common/ConnectionInterface.hpp"
#include "depthai-shared/common/CpuUsage.hpp"
#include "depthai-shared/common/MemoryInfo.hpp"
#include "depthai-shared/datatype/RawIMUData.hpp"
Expand Down Expand Up @@ -596,11 +596,11 @@ class DeviceBase {
std::vector<CameraBoardSocket> getConnectedCameras();

/**
* Get connectivity for device
* Get connection interfaces for device
*
* @returns Vector of connection type
*/
std::vector<Connectivity> getConnectionInterfaces();
std::vector<ConnectionInterface> getConnectionInterfaces();

/**
* Get cameras that are connected to the device with their features/properties
Expand Down
79 changes: 79 additions & 0 deletions include/depthai/pipeline/datatype/MessageGroup.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#pragma once

#include <chrono>
#include <memory>
#include <unordered_map>
#include <vector>

#include "depthai-shared/datatype/RawMessageGroup.hpp"
#include "depthai/pipeline/datatype/Buffer.hpp"

namespace dai {

/**
* MessageGroup message. Carries multiple messages in one.
*/
class MessageGroup : public Buffer {
std::shared_ptr<RawBuffer> serialize() const override;
RawMessageGroup& rawGrp;
std::unordered_map<std::string, std::shared_ptr<ADatatype>> group;

public:
/// Construct MessageGroup message
MessageGroup();
explicit MessageGroup(std::shared_ptr<RawMessageGroup> ptr);
virtual ~MessageGroup() = default;

/// Group
std::shared_ptr<ADatatype> operator[](const std::string& name);
template <typename T>
std::shared_ptr<T> get(const std::string& name) {
return std::dynamic_pointer_cast<T>(group[name]);
}
void add(const std::string& name, const std::shared_ptr<ADatatype>& value);
template <typename T>
void add(const std::string& name, const T& value) {
static_assert(std::is_base_of<ADatatype, T>::value, "T must derive from ADatatype");
group[name] = std::make_shared<T>(value);
rawGrp.group[name] = {value.getRaw(), 0};
}

// Iterators
std::unordered_map<std::string, std::shared_ptr<ADatatype>>::iterator begin();
std::unordered_map<std::string, std::shared_ptr<ADatatype>>::iterator end();

asahtik marked this conversation as resolved.
Show resolved Hide resolved
/**
* True if all messages in the group are in the interval
* @param thresholdNs Maximal interval between messages
*/
bool isSynced(int64_t thresholdNs) const;

/**
* Retrieves interval between the first and the last message in the group.
*/
int64_t getIntervalNs() const;

int64_t getNumMessages() const;

/**
* Gets the names of messages in the group
*/
std::vector<std::string> getMessageNames() const;

/**
* Sets image timestamp related to dai::Clock::now()
*/
MessageGroup& setTimestamp(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> timestamp);

/**
* Sets image timestamp related to dai::Clock::now()
*/
MessageGroup& setTimestampDevice(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> timestamp);

/**
* Retrieves image sequence number
asahtik marked this conversation as resolved.
Show resolved Hide resolved
*/
MessageGroup& setSequenceNum(int64_t sequenceNum);
};

} // namespace dai
3 changes: 3 additions & 0 deletions include/depthai/pipeline/datatype/StreamMessageParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <XLink/XLinkPublicDefines.h>

// project
#include "depthai-shared/datatype/DatatypeEnum.hpp"
#include "depthai-shared/datatype/RawMessageGroup.hpp"
#include "depthai/pipeline/datatype/ADatatype.hpp"

// shared
Expand All @@ -20,6 +22,7 @@ class StreamMessageParser {
public:
static std::shared_ptr<RawBuffer> parseMessage(streamPacketDesc_t* const packet);
static std::shared_ptr<ADatatype> parseMessageToADatatype(streamPacketDesc_t* const packet);
static std::shared_ptr<ADatatype> parseMessageToADatatype(streamPacketDesc_t* const packet, DatatypeEnum& type);
static std::vector<std::uint8_t> serializeMessage(const std::shared_ptr<const RawBuffer>& data);
static std::vector<std::uint8_t> serializeMessage(const RawBuffer& data);
static std::vector<std::uint8_t> serializeMessage(const std::shared_ptr<const ADatatype>& data);
Expand Down
1 change: 1 addition & 0 deletions include/depthai/pipeline/datatypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "datatype/ImageManipConfig.hpp"
#include "datatype/ImgDetections.hpp"
#include "datatype/ImgFrame.hpp"
#include "datatype/MessageGroup.hpp"
#include "datatype/NNData.hpp"
#include "datatype/SpatialImgDetections.hpp"
#include "datatype/SpatialLocationCalculatorConfig.hpp"
Expand Down
28 changes: 28 additions & 0 deletions include/depthai/pipeline/node/MessageDemux.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "depthai-shared/properties/MessageDemuxProperties.hpp"
#include "depthai/pipeline/Node.hpp"

namespace dai {
namespace node {

class MessageDemux : public NodeCRTP<Node, MessageDemux, MessageDemuxProperties> {
public:
constexpr static const char* NAME = "MessageDemux";
MessageDemux(const std::shared_ptr<PipelineImpl>& par, int64_t nodeId);

MessageDemux(const std::shared_ptr<PipelineImpl>& par, int64_t nodeId, std::unique_ptr<Properties> props);

/**
* Input message of type MessageGroup
*/
Input input{*this, "input", Input::Type::SReceiver, {{DatatypeEnum::MessageGroup, false}}};

/**
* A map of outputs, where keys are same as in the input MessageGroup
*/
OutputMap outputs;
asahtik marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace node
} // namespace dai
Loading
Loading