From d572a1b99c19aebc1e25a89f1f37d2cceccc99d0 Mon Sep 17 00:00:00 2001 From: Myron Rodrigues Date: Fri, 27 Sep 2024 19:02:51 +0000 Subject: [PATCH 1/8] allow setting input height --- .../depthai_ros_driver/dai_nodes/nn/detection.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp index 3986f6c4..306f2a82 100644 --- a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp +++ b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "depthai-shared/common/CameraBoardSocket.hpp" #include "depthai/device/DataQueue.hpp" @@ -65,6 +66,9 @@ class Detection : public BaseNode { if(ph->getParam("i_disable_resize")) { width = ph->getOtherNodeParam(socketName, "i_preview_width"); height = ph->getOtherNodeParam(socketName, "i_preview_height"); + } else if(inputWidth.has_value() && inputHeight.has_value()) { + width = inputWidth.value(); + height = inputHeight.value(); } else { width = imageManip->initialConfig.getResizeConfig().width; height = imageManip->initialConfig.getResizeConfig().height; @@ -132,6 +136,12 @@ class Detection : public BaseNode { ptPub = setupOutput(pipeline, ptQName, [&](dai::Node::Input input) { detectionNode->passthrough.link(input); }); } }; + + void setInputDimensions(int width, int height) + { + inputWidth = width; + inputHeight = height; + } /** * @brief Closes the queues for the DetectionNetwork node and the passthrough. */ @@ -173,6 +183,7 @@ class Detection : public BaseNode { std::shared_ptr nnQ, ptQ; std::shared_ptr xoutNN; std::string nnQName, ptQName; + std::optional inputWidth, inputHeight; }; } // namespace nn From b630afa6ba008752612df183532f8047e7b9b3ac Mon Sep 17 00:00:00 2001 From: Myron Rodrigues Date: Fri, 27 Sep 2024 19:03:34 +0000 Subject: [PATCH 2/8] ugliest way to set these parameters, cannot log as well coz no ros node --- .../dai_nodes/nn/nn_wrapper.hpp | 1 + .../src/dai_nodes/nn/nn_wrapper.cpp | 16 ++++++++++++++++ .../src/dai_nodes/sensors/sensor_wrapper.cpp | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp index cfab6975..dbdcfa5e 100644 --- a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp +++ b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp @@ -33,6 +33,7 @@ class NNWrapper : public BaseNode { ~NNWrapper(); void updateParams(const std::vector& params) override; void setupQueues(std::shared_ptr device) override; + void setInputDimensions(int width, int height); void link(dai::Node::Input in, int linkType = 0) override; dai::Node::Input getInput(int linkType = 0) override; virtual void setNames() override; diff --git a/depthai_ros_driver/src/dai_nodes/nn/nn_wrapper.cpp b/depthai_ros_driver/src/dai_nodes/nn/nn_wrapper.cpp index b7d56f80..7fdc89ad 100644 --- a/depthai_ros_driver/src/dai_nodes/nn/nn_wrapper.cpp +++ b/depthai_ros_driver/src/dai_nodes/nn/nn_wrapper.cpp @@ -48,6 +48,22 @@ void NNWrapper::closeQueues() { nnNode->closeQueues(); } +void NNWrapper::setInputDimensions(int width, int height) +{ + auto family = ph->getNNFamily(); + if (family == param_handlers::nn::NNFamily::Yolo) { + auto detectionNode = dynamic_cast*>(nnNode.get()); + if(detectionNode) { + detectionNode->setInputDimensions(width, height); + } + } else if (family == param_handlers::nn::NNFamily::Mobilenet) { + auto detectionNode = dynamic_cast*>(nnNode.get()); + if(detectionNode) { + detectionNode->setInputDimensions(width, height); + } + } +} + void NNWrapper::link(dai::Node::Input in, int linkType) { nnNode->link(in, linkType); } diff --git a/depthai_ros_driver/src/dai_nodes/sensors/sensor_wrapper.cpp b/depthai_ros_driver/src/dai_nodes/sensors/sensor_wrapper.cpp index 6693d579..f1276832 100644 --- a/depthai_ros_driver/src/dai_nodes/sensors/sensor_wrapper.cpp +++ b/depthai_ros_driver/src/dai_nodes/sensors/sensor_wrapper.cpp @@ -69,6 +69,12 @@ SensorWrapper::SensorWrapper(const std::string& daiNodeName, } if(ph->getParam("i_enable_nn")) { nnNode = std::make_unique(daiNodeName + std::string("_nn"), node, pipeline, static_cast(socketID)); + auto sensorWidth = ph->getParam("i_width"); + auto sensorHeight = ph->getParam("i_height"); + auto nn_wrapper = dynamic_cast(nnNode.get()); + if(nn_wrapper) { + nn_wrapper->setInputDimensions(sensorWidth, sensorHeight); + } sensorNode->link(nnNode->getInput(), static_cast(link_types::RGBLinkType::preview)); } RCLCPP_DEBUG(node->get_logger(), "Base node %s created", daiNodeName.c_str()); From eea3f92468c822b5d48acd2611c60e3d288716c1 Mon Sep 17 00:00:00 2001 From: Myron Rodrigues Date: Mon, 30 Sep 2024 12:38:37 +0000 Subject: [PATCH 3/8] set detection input dims from socket dims --- .../dai_nodes/nn/detection.hpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp index 306f2a82..c8b1a7c8 100644 --- a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp +++ b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp @@ -39,7 +39,7 @@ class Detection : public BaseNode { std::shared_ptr node, std::shared_ptr pipeline, const dai::CameraBoardSocket& socket = dai::CameraBoardSocket::CAM_A) - : BaseNode(daiNodeName, node, pipeline) { + : BaseNode(daiNodeName, node, pipeline){ RCLCPP_DEBUG(getLogger(), "Creating node %s", daiNodeName.c_str()); setNames(); detectionNode = pipeline->create(); @@ -66,12 +66,11 @@ class Detection : public BaseNode { if(ph->getParam("i_disable_resize")) { width = ph->getOtherNodeParam(socketName, "i_preview_width"); height = ph->getOtherNodeParam(socketName, "i_preview_height"); - } else if(inputWidth.has_value() && inputHeight.has_value()) { - width = inputWidth.value(); - height = inputHeight.value(); } else { - width = imageManip->initialConfig.getResizeConfig().width; - height = imageManip->initialConfig.getResizeConfig().height; + width = ph->getOtherNodeParam(socketName, "i_width"); + height = ph->getOtherNodeParam(socketName, "i_height"); + // width = imageManip->initialConfig.getResizeConfig().width; + // height = imageManip->initialConfig.getResizeConfig().height; } detConverter = std::make_unique(tfPrefix, width, height, false, ph->getParam("i_get_base_device_timestamp")); @@ -137,11 +136,6 @@ class Detection : public BaseNode { } }; - void setInputDimensions(int width, int height) - { - inputWidth = width; - inputHeight = height; - } /** * @brief Closes the queues for the DetectionNetwork node and the passthrough. */ @@ -183,7 +177,6 @@ class Detection : public BaseNode { std::shared_ptr nnQ, ptQ; std::shared_ptr xoutNN; std::string nnQName, ptQName; - std::optional inputWidth, inputHeight; }; } // namespace nn From c4036806d94c5f1294f359a8e924af4d2d457987 Mon Sep 17 00:00:00 2001 From: Myron Rodrigues Date: Mon, 30 Sep 2024 12:39:36 +0000 Subject: [PATCH 4/8] remove the now unused input dim setter --- .../dai_nodes/nn/nn_wrapper.hpp | 2 +- .../src/dai_nodes/nn/nn_wrapper.cpp | 22 +++---------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp index dbdcfa5e..bbd4732e 100644 --- a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp +++ b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "depthai-shared/common/CameraBoardSocket.hpp" #include "depthai_ros_driver/dai_nodes/base_node.hpp" @@ -33,7 +34,6 @@ class NNWrapper : public BaseNode { ~NNWrapper(); void updateParams(const std::vector& params) override; void setupQueues(std::shared_ptr device) override; - void setInputDimensions(int width, int height); void link(dai::Node::Input in, int linkType = 0) override; dai::Node::Input getInput(int linkType = 0) override; virtual void setNames() override; diff --git a/depthai_ros_driver/src/dai_nodes/nn/nn_wrapper.cpp b/depthai_ros_driver/src/dai_nodes/nn/nn_wrapper.cpp index 7fdc89ad..65a580e1 100644 --- a/depthai_ros_driver/src/dai_nodes/nn/nn_wrapper.cpp +++ b/depthai_ros_driver/src/dai_nodes/nn/nn_wrapper.cpp @@ -20,15 +20,15 @@ NNWrapper::NNWrapper(const std::string& daiNodeName, auto family = ph->getNNFamily(); switch(family) { case param_handlers::nn::NNFamily::Yolo: { - nnNode = std::make_unique>(getName(), getROSNode(), pipeline); + nnNode = std::make_unique>(getName(), getROSNode(), pipeline, socket); break; } case param_handlers::nn::NNFamily::Mobilenet: { - nnNode = std::make_unique>(getName(), getROSNode(), pipeline); + nnNode = std::make_unique>(getName(), getROSNode(), pipeline, socket); break; } case param_handlers::nn::NNFamily::Segmentation: { - nnNode = std::make_unique(getName(), getROSNode(), pipeline); + nnNode = std::make_unique(getName(), getROSNode(), pipeline, socket); break; } } @@ -48,22 +48,6 @@ void NNWrapper::closeQueues() { nnNode->closeQueues(); } -void NNWrapper::setInputDimensions(int width, int height) -{ - auto family = ph->getNNFamily(); - if (family == param_handlers::nn::NNFamily::Yolo) { - auto detectionNode = dynamic_cast*>(nnNode.get()); - if(detectionNode) { - detectionNode->setInputDimensions(width, height); - } - } else if (family == param_handlers::nn::NNFamily::Mobilenet) { - auto detectionNode = dynamic_cast*>(nnNode.get()); - if(detectionNode) { - detectionNode->setInputDimensions(width, height); - } - } -} - void NNWrapper::link(dai::Node::Input in, int linkType) { nnNode->link(in, linkType); } From 99f181f16d533ca6cc2847e9adc889cf39a68808 Mon Sep 17 00:00:00 2001 From: Myron Rodrigues Date: Mon, 30 Sep 2024 12:40:10 +0000 Subject: [PATCH 5/8] remove calls to input setter --- depthai_ros_driver/src/dai_nodes/sensors/sensor_wrapper.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/depthai_ros_driver/src/dai_nodes/sensors/sensor_wrapper.cpp b/depthai_ros_driver/src/dai_nodes/sensors/sensor_wrapper.cpp index f1276832..6693d579 100644 --- a/depthai_ros_driver/src/dai_nodes/sensors/sensor_wrapper.cpp +++ b/depthai_ros_driver/src/dai_nodes/sensors/sensor_wrapper.cpp @@ -69,12 +69,6 @@ SensorWrapper::SensorWrapper(const std::string& daiNodeName, } if(ph->getParam("i_enable_nn")) { nnNode = std::make_unique(daiNodeName + std::string("_nn"), node, pipeline, static_cast(socketID)); - auto sensorWidth = ph->getParam("i_width"); - auto sensorHeight = ph->getParam("i_height"); - auto nn_wrapper = dynamic_cast(nnNode.get()); - if(nn_wrapper) { - nn_wrapper->setInputDimensions(sensorWidth, sensorHeight); - } sensorNode->link(nnNode->getInput(), static_cast(link_types::RGBLinkType::preview)); } RCLCPP_DEBUG(node->get_logger(), "Base node %s created", daiNodeName.c_str()); From d7a8919ec75c70a2238720feb2eaae08050e2336 Mon Sep 17 00:00:00 2001 From: Myron Rodrigues Date: Mon, 30 Sep 2024 12:51:57 +0000 Subject: [PATCH 6/8] add desqueeze parameter --- .../include/depthai_ros_driver/dai_nodes/nn/detection.hpp | 7 ++++--- .../depthai_ros_driver/param_handlers/nn_param_handler.hpp | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp index c8b1a7c8..06c04a87 100644 --- a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp +++ b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp @@ -66,11 +66,12 @@ class Detection : public BaseNode { if(ph->getParam("i_disable_resize")) { width = ph->getOtherNodeParam(socketName, "i_preview_width"); height = ph->getOtherNodeParam(socketName, "i_preview_height"); - } else { + } else if(ph->getParam("i_desqueeze_output")) { width = ph->getOtherNodeParam(socketName, "i_width"); height = ph->getOtherNodeParam(socketName, "i_height"); - // width = imageManip->initialConfig.getResizeConfig().width; - // height = imageManip->initialConfig.getResizeConfig().height; + } else { + width = imageManip->initialConfig.getResizeConfig().width; + height = imageManip->initialConfig.getResizeConfig().height; } detConverter = std::make_unique(tfPrefix, width, height, false, ph->getParam("i_get_base_device_timestamp")); diff --git a/depthai_ros_driver/include/depthai_ros_driver/param_handlers/nn_param_handler.hpp b/depthai_ros_driver/include/depthai_ros_driver/param_handlers/nn_param_handler.hpp index 40656c1b..b22fb0de 100644 --- a/depthai_ros_driver/include/depthai_ros_driver/param_handlers/nn_param_handler.hpp +++ b/depthai_ros_driver/include/depthai_ros_driver/param_handlers/nn_param_handler.hpp @@ -40,6 +40,7 @@ class NNParamHandler : public BaseParamHandler { template void declareParams(std::shared_ptr nn, std::shared_ptr imageManip) { declareAndLogParam("i_disable_resize", false); + declareAndLogParam("i_desqueeze_output", false); declareAndLogParam("i_enable_passthrough", false); declareAndLogParam("i_enable_passthrough_depth", false); declareAndLogParam("i_get_base_device_timestamp", false); From c1d996f5da8f33e1aafb54744bd46236ebd9449d Mon Sep 17 00:00:00 2001 From: Myron Rodrigues Date: Mon, 30 Sep 2024 13:19:45 +0000 Subject: [PATCH 7/8] remove unused optional header --- .../include/depthai_ros_driver/dai_nodes/nn/detection.hpp | 1 - .../include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp | 1 - 2 files changed, 2 deletions(-) diff --git a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp index 06c04a87..2536cc11 100644 --- a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp +++ b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp @@ -3,7 +3,6 @@ #include #include #include -#include #include "depthai-shared/common/CameraBoardSocket.hpp" #include "depthai/device/DataQueue.hpp" diff --git a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp index bbd4732e..cfab6975 100644 --- a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp +++ b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp @@ -3,7 +3,6 @@ #include #include #include -#include #include "depthai-shared/common/CameraBoardSocket.hpp" #include "depthai_ros_driver/dai_nodes/base_node.hpp" From 3f24a9540488e294b9e805a90284b2c054ad1f3e Mon Sep 17 00:00:00 2001 From: Myron Rodrigues Date: Mon, 30 Sep 2024 13:20:39 +0000 Subject: [PATCH 8/8] formatting --- .../include/depthai_ros_driver/dai_nodes/nn/detection.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp index 2536cc11..f0798124 100644 --- a/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp +++ b/depthai_ros_driver/include/depthai_ros_driver/dai_nodes/nn/detection.hpp @@ -38,7 +38,7 @@ class Detection : public BaseNode { std::shared_ptr node, std::shared_ptr pipeline, const dai::CameraBoardSocket& socket = dai::CameraBoardSocket::CAM_A) - : BaseNode(daiNodeName, node, pipeline){ + : BaseNode(daiNodeName, node, pipeline) { RCLCPP_DEBUG(getLogger(), "Creating node %s", daiNodeName.c_str()); setNames(); detectionNode = pipeline->create();