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

Add option to prepend timestamp to image filename in image_saver node #806

Merged
merged 1 commit into from
May 24, 2023
Merged
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions image_view/src/nodes/image_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <std_srvs/Trigger.h>

boost::format g_format;
bool stamped_filename;
bool save_all_image, save_image_service;
std::string encoding;
bool request_start_end;
Expand Down Expand Up @@ -164,6 +165,14 @@ class Callbacks {
} catch (...) { g_format.clear(); }

if ( save_all_image || save_image_service ) {

if (stamped_filename) {
std::stringstream ss;
ss << ros::Time::now().toNSec();
std::string timestamp_str = ss.str();
filename.insert(0,timestamp_str);
}

cv::imwrite(filename, image);
ROS_INFO("Saved image %s", filename.c_str());

Expand Down Expand Up @@ -205,6 +214,7 @@ int main(int argc, char** argv)
ros::NodeHandle local_nh("~");
std::string format_string;
local_nh.param("filename_format", format_string, std::string("left%04i.%s"));
local_nh.param("stamped_filename", stamped_filename, false);
local_nh.param("encoding", encoding, std::string("bgr8"));
local_nh.param("save_all_image", save_all_image, true);
local_nh.param("request_start_end", request_start_end, false);
Expand Down