Skip to content

Commit

Permalink
Merge branch 'v3_develop' of github.com:luxonis/depthai-core into rvc…
Browse files Browse the repository at this point in the history
…2_img_transformations_v2
  • Loading branch information
asahtik committed Jan 8, 2025
2 parents 46f478f + cc5ec37 commit cc49040
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ void bind_detectionnetwork(pybind11::module& m, void* pCallstack) {
py::arg("input"),
py::arg("model"),
py::arg("fps") = 30.0f)
.def("build",
([](DetectionNetwork& self, const std::shared_ptr<Camera>& input, std::string model, float fps) {
return self.build(input, NNModelDescription{model}, fps);
}),
py::arg("input"),
py::arg("model"),
py::arg("fps") = 30.0f)
.def("build",
py::overload_cast<const std::shared_ptr<Camera>&, NNArchive, float>(&DetectionNetwork::build),
py::arg("input"),
Expand Down
3 changes: 3 additions & 0 deletions bindings/python/src/pipeline/node/NeuralNetworkBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ void bind_neuralnetwork(pybind11::module& m, void* pCallstack){
.def("build", py::overload_cast<dai::Node::Output&, const NNArchive&>(&NeuralNetwork::build), py::arg("input"), py::arg("nnArchive"), DOC(dai, node, NeuralNetwork, build))
.def("build", py::overload_cast<const std::shared_ptr<Camera>&, dai::NNModelDescription, float>(&NeuralNetwork::build), py::arg("input"), py::arg("modelDesc"), py::arg("fps")=30.0f, DOC(dai, node, NeuralNetwork, build,2))
.def("build", py::overload_cast<const std::shared_ptr<Camera>&, dai::NNArchive, float>(&NeuralNetwork::build), py::arg("input"), py::arg("nnArchive"), py::arg("fps")=30.0f, DOC(dai, node, NeuralNetwork, build, 3))
.def("build", [](NeuralNetwork& self, const std::shared_ptr<Camera>& input, const std::string& model, float fps) {
return self.build(input, NNModelDescription{model}, fps);
}, py::arg("input"), py::arg("model"), py::arg("fps")=30.0f, DOC(dai, node, NeuralNetwork, build))
.def("setBlob", py::overload_cast<dai::OpenVINO::Blob>(&NeuralNetwork::setBlob), py::arg("blob"), DOC(dai, node, NeuralNetwork, setBlob))
.def("setBlob", py::overload_cast<const dai::Path&>(&NeuralNetwork::setBlob), py::arg("path"), DOC(dai, node, NeuralNetwork, setBlob, 2))
.def("setModelPath",
Expand Down
19 changes: 19 additions & 0 deletions bindings/python/src/pipeline/node/NodeBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ void NodeBindings::bind(pybind11::module& m, void* pCallstack) {
static_cast<Node& (Node::Input::*)()>(&Node::Input::getParent),
py::return_value_policy::reference_internal,
DOC(dai, Node, Input, getParent))
.def("getPossibleDatatypes", &Node::Input::getPossibleDatatypes, DOC(dai, Node, Input, getPossibleDatatypes))
.def("setPossibleDatatypes", &Node::Input::setPossibleDatatypes, py::arg("types"), DOC(dai, Node, Input, setPossibleDatatypes))
.def("setPossibleDatatypes", [](Node::Input& input, const std::vector<std::tuple<DatatypeEnum, bool>>& types) {
std::vector<Node::DatatypeHierarchy> converted;
converted.reserve(types.size());
for(const auto& t : types) {
converted.emplace_back(std::get<0>(t), std::get<1>(t));
}
input.setPossibleDatatypes(converted);
}, py::arg("types"), DOC(dai, Node, Input, setPossibleDatatypes))
.def("setWaitForMessage", &Node::Input::setWaitForMessage, py::arg("waitForMessage"), DOC(dai, Node, Input, setWaitForMessage))
.def("getWaitForMessage", &Node::Input::getWaitForMessage, DOC(dai, Node, Input, getWaitForMessage))
.def("setReusePreviousMessage", &Node::Input::setReusePreviousMessage, py::arg("reusePreviousMessage"), DOC(dai, Node, Input, setReusePreviousMessage))
Expand All @@ -336,6 +346,15 @@ void NodeBindings::bind(pybind11::module& m, void* pCallstack) {
py::arg("possibleDatatypes") = Node::OutputDescription{}.types,
py::keep_alive<1, 0>())
.def("getPossibleDatatypes", &Node::Output::getPossibleDatatypes, DOC(dai, Node, Output, getPossibleDatatypes))
.def("setPossibleDatatypes", &Node::Output::setPossibleDatatypes, py::arg("types"), DOC(dai, Node, Output, setPossibleDatatypes))
.def("setPossibleDatatypes", [](Node::Output& output, const std::vector<std::tuple<DatatypeEnum, bool>>& types) {
std::vector<Node::DatatypeHierarchy> converted;
converted.reserve(types.size());
for(const auto& t : types) {
converted.emplace_back(std::get<0>(t), std::get<1>(t));
}
output.setPossibleDatatypes(converted);
}, py::arg("types"), DOC(dai, Node, Output, setPossibleDatatypes))
.def("getParent",
static_cast<const Node& (Node::Output::*)() const>(&Node::Output::getParent),
py::return_value_policy::reference_internal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ void bind_spatialdetectionnetwork(pybind11::module& m, void* pCallstack){
spatialDetectionNetwork
// Copied from NN node
.def("build", py::overload_cast<const std::shared_ptr<Camera>&, const std::shared_ptr<StereoDepth>&, NNModelDescription, float>(&SpatialDetectionNetwork::build), py::arg("input"), py::arg("stereo"), py::arg("model"), py::arg("fps") = 30.0f, DOC(dai, node, SpatialDetectionNetwork, build))
.def("build", ([](SpatialDetectionNetwork& self, const std::shared_ptr<Camera>& input, const std::shared_ptr<StereoDepth>& stereo, std::string model, float fps) {
return self.build(input, stereo, NNModelDescription{model}, fps);
}), py::arg("input"), py::arg("stereo"), py::arg("model"), py::arg("fps") = 30.0f, DOC(dai, node, SpatialDetectionNetwork, build, 2))
.def("build", py::overload_cast<const std::shared_ptr<Camera>&, const std::shared_ptr<StereoDepth>&, NNArchive, float>(&SpatialDetectionNetwork::build), py::arg("input"), py::arg("stereo"), py::arg("nnArchive"), py::arg("fps") = 30.0f, DOC(dai, node, SpatialDetectionNetwork, build, 2))
.def("setBlobPath", &SpatialDetectionNetwork::setBlobPath, py::arg("path"), DOC(dai, node, SpatialDetectionNetwork, setBlobPath))
.def("setNumPoolFrames", &SpatialDetectionNetwork::setNumPoolFrames, py::arg("numFrames"), DOC(dai, node, SpatialDetectionNetwork, setNumPoolFrames))
Expand Down
17 changes: 17 additions & 0 deletions examples/python/HostNodes/threaded_host_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ def __init__(self, name: str):
self.input = self.createInput()
self.output = self.createOutput()

# Possible API 1:
self.input.setPossibleDatatypes([dai.Node.DatatypeHierarchy(dai.DatatypeEnum.ImgFrame, True)])
self.output.setPossibleDatatypes([dai.Node.DatatypeHierarchy(dai.DatatypeEnum.ImgFrame, True)])

# Possible API 2:
self.input.setPossibleDatatypes([
(dai.DatatypeEnum.ImgFrame, True),
(dai.DatatypeEnum.Buffer, True)
])
self.output.setPossibleDatatypes([
(dai.DatatypeEnum.ImgFrame, True),
(dai.DatatypeEnum.Buffer, True)
])



def onStart(self):
print("Hello, this is", self.name)

Expand All @@ -24,6 +40,7 @@ class TestSink(dai.node.ThreadedHostNode):
def __init__(self, name: str):
super().__init__()
self.input = self.createInput()

self.name = name

def onStart(self):
Expand Down
19 changes: 16 additions & 3 deletions include/depthai/pipeline/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ class Node : public std::enable_shared_from_this<Node> {
/**
* Get possible datatypes that can be sent
*/
std::vector<DatatypeHierarchy> getPossibleDatatypes() const {
return desc.types;
}
std::vector<DatatypeHierarchy> getPossibleDatatypes() const;

/**
* Set possible datatypes that can be sent
*/
void setPossibleDatatypes(std::vector<DatatypeHierarchy> types);

/**
* Check if this output and given input are on the same pipeline.
Expand Down Expand Up @@ -378,6 +381,16 @@ class Node : public std::enable_shared_from_this<Node> {
*/
bool getWaitForMessage() const;

/**
* Get possible datatypes that can be received
*/
std::vector<DatatypeHierarchy> getPossibleDatatypes() const;

/**
* Set possible datatypes that can be received
*/
void setPossibleDatatypes(std::vector<DatatypeHierarchy> types);

/**
* Equivalent to setWaitForMessage but with inverted logic.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/pipeline/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,4 +731,20 @@ std::vector<std::pair<Node::Input&, std::shared_ptr<Capability>>> Node::getRequi
DAI_CHECK_V(false, "Node '{}' doesn't support node to node linking. Please link outputs <--> inputs manually.", getName());
}

void Node::Output::setPossibleDatatypes(std::vector<Node::DatatypeHierarchy> types) {
desc.types = std::move(types);
}

std::vector<Node::DatatypeHierarchy> Node::Output::getPossibleDatatypes() const {
return desc.types;
}

void Node::Input::setPossibleDatatypes(std::vector<Node::DatatypeHierarchy> types) {
possibleDatatypes = std::move(types);
}

std::vector<Node::DatatypeHierarchy> Node::Input::getPossibleDatatypes() const {
return possibleDatatypes;
}

} // namespace dai

0 comments on commit cc49040

Please sign in to comment.