Ask Your Question
0

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 -0500

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
1

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

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;
        try
        {
          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

Comments

thank you very much it works successfuly

toupass gravatar imagetoupass ( 2014-11-21 05:21:54 -0500 )edit

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

Torsten gravatar imageTorsten ( 2014-11-21 05:49:54 -0500 )edit
2

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

tfoote gravatar image

I suggest that you take a look at rosbag

edit flag offensive delete link more

Comments

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 imageTorsten ( 2014-11-20 03:57:02 -0500 )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 imagetoupass ( 2014-11-20 05:20:07 -0500 )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

2 followers

Stats

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

Seen: 121 times

Last updated: Nov 20 '14