Home | Tutorials | Wiki | Issues
Ask Your Question
0

Data corruption from camera sensor

asked 2015-12-16 09:08:46 -0500

Nic Greenway gravatar image

Hi All. I could do with advice on how to investigate what looks like intermittent corrupt data being returned from a camera sensor.

I'm accessing the camera image from a model plugin, but when I render the resulting images occasionally the scene will be briefly replaced with a mishmash of bright colours.

Frequency of occurrence: 1 or 2 times/minute, usually for less than one second each time. Seems to happen less often if the robot is stationary, i.e. it happens more frequently the more the contents of the scene are changing

On the visualization screen projected from the robot within the Gazebo UI, there is no such corruption visible

I'm accessing the data from within the plugin OnUpdate event, and actually extracting it using:

  gazebo::sensors::SensorPtr s2 = gazebo::sensors::get_sensor("camera")
  gazebo::sensors::CameraSensor *cs = dynamic_cast<gazebo::sensors::CameraSensor*>(sp.get());
  const int COLOR_COMPONENTS = 3;
  int _width = cs->GetImageWidth();
  int _height = cs->GetImageHeight();
  unsigned char buffer[_width*_height*COLOR_COMPONENTS];
  std::stringstream ss;

  ss << cs->GetImageData();
  ss >> buffer;

Camera SDF:

  <sensor name="camera" type="camera">
    <pose>0.305 0 0.1 0 -0 0</pose>
    <camera>
      <horizontal_fov>1.0</horizontal_fov>
      <image>
        <width>20</width>
        <height>10</height>
      </image>
      <clip>
        <near>0.01</near>
        <far>500</far>
      </clip>
    </camera>
    <always_on>1</always_on>
    <update_rate>20</update_rate>
    <visualize>true</visualize>
  </sensor>

I'm not all that experienced with Gazebo, so advice appreciated on just where I start looking to fix this.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-12-17 12:50:57 -0500

Nic Greenway gravatar image

Fixed - the issue wasn't Gazebo at all, it was my treatment of the image, specifically using a stringstream to process it. Replacing that sorted everything out.

edit flag offensive delete link more
0

answered 2015-12-16 12:03:46 -0500

nkoenig gravatar image

You are probably accessing the camera data during a render update. You should use a sensor plugin like the camera plugin. The OnNewFrame function will give you the buffer you need.

edit flag offensive delete link more

Comments

Thanks for the advice: although it wasn't the cause of my problem, I have switched to using OnNewFrame anyway

Nic Greenway gravatar imageNic Greenway ( 2015-12-17 12:52:03 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-12-16 09:08:46 -0500

Seen: 240 times

Last updated: Dec 17 '15