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

How to save camera image when needed?

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

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?

Thanks!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

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

gvdhoorn gravatar image

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

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

edit flag offensive delete link more

Comments

Thank you! Work like a charm.

wy3 gravatar image wy3  ( 2017-06-26 04:15:43 -0500 )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 -0500 )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 -0500 )edit
0

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

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

Comments

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

Question Tools

Stats

Asked: 2017-06-22 07:26:59 -0500

Seen: 2,215 times

Last updated: Jun 22 '17