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..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" @@ -91,6 +92,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 +146,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 {