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 imagewy3 ( 2017-06-26 04:15:43 -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 imagewy3 ( 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 imagewy3 ( 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: 783 times

Last updated: Jun 22 '17