From 0173abe3198f718323ea14c012fe3075daa7aea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Fri, 19 Jan 2024 13:53:57 +0100 Subject: [PATCH 1/2] ROS 2: Add option to prepend timestamp to image filename in image_saver node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alejandro Hernández Cordero --- image_view/include/image_view/image_saver_node.hpp | 1 + image_view/src/image_saver_node.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/image_view/include/image_view/image_saver_node.hpp b/image_view/include/image_view/image_saver_node.hpp index 217ea71d2..af3b0434c 100644 --- a/image_view/include/image_view/image_saver_node.hpp +++ b/image_view/include/image_view/image_saver_node.hpp @@ -70,6 +70,7 @@ class ImageSaverNode private: boost::format g_format; + bool stamped_filename_; bool save_all_image_{false}; bool save_image_service_{false}; std::string encoding_; diff --git a/image_view/src/image_saver_node.cpp b/image_view/src/image_saver_node.cpp index 5760b1488..d9ea72736 100644 --- a/image_view/src/image_saver_node.cpp +++ b/image_view/src/image_saver_node.cpp @@ -91,6 +91,7 @@ ImageSaverNode::ImageSaverNode(const rclcpp::NodeOptions & options) format_string = this->declare_parameter("filename_format", std::string("left%04i.%s")); encoding_ = this->declare_parameter("encoding", std::string("bgr8")); save_all_image_ = this->declare_parameter("save_all_image", true); + stamped_filename_ = this->declare_parameter("stamped_filename", false); request_start_end_ = this->declare_parameter("request_start_end", false); g_format.parse(format_string); @@ -144,6 +145,13 @@ bool ImageSaverNode::saveImage( } if (save_all_image_ || save_image_service_) { + if (stamped_filename_) { + std::stringstream ss; + ss << this->now().nanoseconds(); + std::string timestamp_str = ss.str(); + filename.insert(0, timestamp_str); + } + if (cv::imwrite(filename, image)) { RCLCPP_INFO(this->get_logger(), "Saved image %s", filename.c_str()); } else { From f9f0dd34088a10461d2294912d4b20e7aa3e4456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Fri, 19 Jan 2024 13:55:23 +0100 Subject: [PATCH 2/2] Added include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alejandro Hernández Cordero --- image_view/src/image_saver_node.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/image_view/src/image_saver_node.cpp b/image_view/src/image_saver_node.cpp index d9ea72736..9707f8a1b 100644 --- a/image_view/src/image_saver_node.cpp +++ b/image_view/src/image_saver_node.cpp @@ -48,6 +48,7 @@ #include #include +#include #include #include "cv_bridge/cv_bridge.hpp"