ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

I am Beginner in ROS.My USB camera is running on ROS.please i need a help, how to save an sensor_msgs/Image to a create file?

asked 2014-11-19 08:52:32 -0600

toupass gravatar image

I am Beginner in ROS.My USB camera is running on ROS.please i need a help, how to save an sensor_msgs/Image to a create file?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-11-20 05:57:14 -0600

Torsten gravatar image

If you need a "screenshot", you have two possibilities:

  1. Use system-screenshot ability and take a screenshot of the image_view output.
  2. Write a little Node / Nodelet which listen to a keyboard shortcut and then write the current image to file, for e.g. with cv_bridge functionality.

    void save_image(const sensor_msgs::ImageConstPtr img, const std::string prefix)
        // May want to view raw bayer data
        // NB: This is hacky, but should be OK since we have only one image CB.
        if (img->encoding.find("bayer") != std::string::npos)
          boost::const_pointer_cast<sensor_msgs::image>(img)->encoding = "mono8";

        cv::Mat image;
          image = cv_bridge::toCvShare(img, "bgr8")->image;
        } catch(cv_bridge::Exception)
          ROS_ERROR("Unable to convert %s image to bgr8", img->encoding.c_str());
        std::string directory = std::string(getenv("HOME")) + "/catkin_ws/video_dumper_jpeg/";
        std::string filename = (filename_format_ % prefix % count_ ).str();
        cv::imwrite(directory + filename, image);
edit flag offensive delete link more


thank you very much it works successfuly

toupass gravatar image toupass  ( 2014-11-21 05:21:54 -0600 )edit

You are welcome. Then please upvote and mark the answer as correct. Thank you!

Torsten gravatar image Torsten  ( 2014-11-21 05:49:54 -0600 )edit

answered 2014-11-19 23:02:54 -0600

tfoote gravatar image

I suggest that you take a look at rosbag

edit flag offensive delete link more


After you have recorded a rosbag, you could extract the images using the image_view extract functionality. You have to run the following and you have to "play" the rosbag you've recorded.

rosrun image_view extract_images image:=/front_camera/camera/image_raw _image_transport:=compressed
Torsten gravatar image Torsten  ( 2014-11-20 03:57:02 -0600 )edit

thank you for the faster answer. unfortunately is not what i wanted. i will like to save snapshot of my runningcamera in a particular file(as jpeg or png frame). I will be very happy if you can help me. thank you in advance.

toupass gravatar image toupass  ( 2014-11-20 05:20:07 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2014-11-19 08:52:32 -0600

Seen: 287 times

Last updated: Nov 20 '14