ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

save subscribed image when service is called

asked 2012-08-07 16:31:26 -0600

atsushi_tsuda gravatar image

Hi all,

Is there any package to save subscribed image when service is called?

I also want to set filename format ("frame%04i.jpg", for example) to get sequential numbered image and save directory with rosparam.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-11-12 22:13:53 -0600

timster gravatar image

I recommend using OpenCV for writing images. Generate a file name like this:

std::ostringstream jpg_filename;
jpg_filename << file_path << "frame" << count << ".jpg";
++count;

I guess there should be a variant to create a printf style formatted string too, but I haven't tried anything.

If you are not doing so already, you need to convert your sensor_msgs::Image to cv::Mat format. There is a nice tutorial for that.

And finally save your image.

cv::imwrite(jpg_filename.str(), your_cv_mat);

Make sure to define OpenCV as a dependency and include the right headers:

#include <fstream>
#include <opencv2/highgui/highgui.hpp>

Best

Tim

edit flag offensive delete link more

Comments

Small note: Boost.Format should be used over printf in C++.

Thomas gravatar image Thomas  ( 2013-11-13 16:54:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2012-08-07 16:31:26 -0600

Seen: 272 times

Last updated: Nov 12 '13