Home | Tutorials | Wiki | Issues
Ask Your Question

how to read images from a camera in the Gazebo?

asked 2017-08-14 05:06:58 -0500

langong gravatar image

hi, everyone, I have the same problem with this http://answers.gazebosim.org/question..., I want to read the images from a camera in the gazebo 6.5, and input the images to the c++ program of image processing. I try to follow the above tips to change the code of CameraDump::OnNewFrame(), but I it is not working. So, can anybody give me hands or show me how you did it? Thanks a lot!

edit retag flag offensive close merge delete


actually, my question is about the example https://bitbucket.org/osrf/gazebo/src/ada35b395c9d/examples/plugins/camera/?at=gazebo6 mentioned in the answer

langong gravatar imagelangong ( 2017-08-14 08:49:27 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-08-14 19:13:47 -0500

iche033 gravatar image

the image data is given by the unsigned char *_image variable. You also get width, height, and format (R8G8B8 for a standard camera) information in the callback, you should be able to feed those to your image processing program.

edit flag offensive delete link more


hi, I am going to use GetImageData (gazebo 6.5) to read the images, But now, I don't know how to use this function, I didn't find any example. Can you show me an example? or do you have any ideas for my problem. Thank you very much!

langong gravatar imagelangong ( 2017-08-15 01:56:11 -0500 )edit

my problem is I don't know how to get the image data, I try to follow the above link, but it is not working. can you help me?

langong gravatar imagelangong ( 2017-08-15 02:08:29 -0500 )edit

I would suggest to use the plugin and get the image data that way. You have a pointer to the image data in memory. Can you describe what you mean by not working? Does this example save frames in the tmp folder? https://bitbucket.org/osrf/gazebo/src/ada35b395c9d/examples/plugins/camera/?at=gazebo6

iche033 gravatar imageiche033 ( 2017-08-15 12:00:37 -0500 )edit

hi, Now, the camera_dump.cc and camera_move.cc is working, The image was saved in the folder and the camera was moving. But, I want to read image data in memory, not save in disk. Because I need image data to do image processing real time. Does the function GetImageData() read image data? I try to using GetImageData() to read image data, but it always returns NULL. Maybe I do not know how to use GetImageData(). Can help me? Thanks a lot!

langong gravatar imagelangong ( 2017-08-16 03:40:21 -0500 )edit

another question: how can I change the update rate of saving the image in the camera_dump.cc. For instance, save an image per 0.5 seconds.

langong gravatar imagelangong ( 2017-08-16 08:47:07 -0500 )edit

if you look at camera_dump, it calls this->parentSensor->GetCamera()->SaveFrame and pass in the _image data. So just modify the plugin to not call that function and it won't save to disk. To change update rate, edit the world file and change the update rate for the camera sensor.

iche033 gravatar imageiche033 ( 2017-08-16 12:10:11 -0500 )edit

it is working. Thank you very much.

langong gravatar imagelangong ( 2017-08-21 10:19:56 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-08-14 05:06:58 -0500

Seen: 332 times

Last updated: Aug 14 '17