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

How to save camera image when needed?

asked 2017-06-22 07:26:59 -0600

wy3 gravatar image

I am currently following this tutorial to publish image messages using the camera plugin. I can totally subscribe the image_raw topic and save every published image message, but that's not what I need.

I am using gazebo to collect image dataset of object manipulation. So ideally I need to capture (save to file) one image after some manipulation actions, then continue with the next round of manipulation and image capturing. So it is like a service request to save the image when needed rather than save images all the time. However, the only source of image I know in gazebo is the image topic. Does anyone have a better idea on how to do that?


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-06-22 07:31:02 -0600

gvdhoorn gravatar image

updated 2017-06-22 07:31:15 -0600

One option would be to use ros::topic::waitForMessage(..) (docs).

edit flag offensive delete link more


Thank you! Work like a charm.

wy3 gravatar image wy3  ( 2017-06-26 04:15:43 -0600 )edit

Hello, i was wondering how to update the msg content? I used this waitForMessage in a for loop but every time i call it, the msg content seems the same. Basically, I just tried to save the image when moving to a new position. Thanks

houhao gravatar image houhao  ( 2021-06-09 04:15:01 -0600 )edit

Please do not post follow-up questions in comments under 5 year old questions with accepted answers. This has almost zero visibility. Post a new question instead.

But as a quick comment: if used correctly, waitForMessage(..) will return new messages each time. I don't know why it doesn't work for you. Please include more detail about how you're calling the function in your new post.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-09 04:18:05 -0600 )edit

answered 2017-06-22 09:21:54 -0600

sihe gravatar image

Here would be my idea for a rather simple approach: write a node which:

  • takes as input the number of images it should save
  • everytime it's launched, records the number of requested images, saves them, and terminates again.
  • you thus would need to launch every time you want to capture one or several images

Of course you could then start to make the node more sophisticated, and for example use a rosservice to trigger the capturing of one or several images, which would eliminate the need to terminate the node. But actually I would say every time sending a rosservice request is just as much "work" as starting the node everytime you want to record the images.

edit flag offensive delete link more


Thank you for your answer. It is totally an option write a node which start and stop other nodes.

wy3 gravatar image wy3  ( 2017-06-26 04:27:41 -0600 )edit

It turns out that wait_for_message actually implement this subscribe once and unregister scheme as you mentioned.

wy3 gravatar image wy3  ( 2017-07-04 09:02:15 -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: 2017-06-22 07:26:59 -0600

Seen: 1,920 times

Last updated: Jun 22 '17