gazebosim / gazebo-classic

Gazebo classic. For the latest version, see https://github.com/gazebosim/gz-sim
http://classic.gazebosim.org/
Other
1.17k stars 477 forks source link

Gazebo 8 DepthCamera ImageData returns all gray image for config and code that worked in gazebo7 #2392

Open osrf-migration opened 6 years ago

osrf-migration commented 6 years ago

Original report (archived issue) by Andrew Somerville (Bitbucket: catskul).


In Gazebo8 Calls to DepthCamera()->ImageData() (DepthCameraSensor::ImageData) from a return an image with values that hover around 128.

Identical configuration and code using Gazebo7 returned a valid image which is the same as it would be with a normal CameraSensor.

Duplicating the camera in the sdf (one as type "camera" and one as type "depth") results in functional camera which works as a workaround to the apparently broken ImageData interface of the DepthCameraSensor.

I checked the history of rendering/DepthCamera.cc and rendering/Camera.cc and didn't see any smoking guns. sensors/DepthCameraSensor.cc and sensors/CameraSensor.cc were harder

Bug can be exercised by adding "./images" below the "camera" tag of any currently working sdf sensor type="depth". Saved images will all be gray.

osrf-migration commented 6 years ago

Original comment by Andrew Somerville (Bitbucket: catskul).


Related gazebo answers post here: http://answers.gazebosim.org/question/18137/have-the-semantics-of-imagedata-coming-from-a-depth-camera-changed-between-gazebo7-and-gazebo8/

osrf-migration commented 6 years ago

Original comment by Nate Koenig (Bitbucket: Nathan Koenig).


Are you using Gazebo 8.2?

osrf-migration commented 6 years ago

Original comment by Andrew Somerville (Bitbucket: catskul).


Yes. 8.2.0 from the current installer.

osrf-migration commented 6 years ago

Original comment by Ian Chen (Bitbucket: Ian Chen, GitHub: iche033).


I created a simple sensor plugin to test this in gazebo8. Here're the relevant functions with calls to DepthCamera::ImageData in OnNewImageFrame:

/////////////////////////////////////////////////
void DepthCameraPlugin::Load(sensors::SensorPtr _sensor,
                              sdf::ElementPtr /*_sdf*/)
{
  this->parentSensor =
    std::dynamic_pointer_cast<sensors::DepthCameraSensor>(_sensor);
  this->depthCamera = this->parentSensor->DepthCamera();

  this->newImageFrameConnection = this->depthCamera->ConnectNewImageFrame(
      std::bind(&DepthCameraPlugin::OnNewImageFrame,
        this, std::placeholders::_1, std::placeholders::_2,
        std::placeholders::_3, std::placeholders::_4, std::placeholders::_5));

  this->parentSensor->SetActive(true);
}

/////////////////////////////////////////////////
void DepthCameraPlugin::OnNewImageFrame(const unsigned char * _image,
                              unsigned int _width,
                              unsigned int _height,
                              unsigned int _depth,
                              const std::string &_format)
{
    common::Image image;
    image.SetFromData(this->depthCamera->ImageData(), 
      _width, _height, common::Image::ConvertPixelFormat(_format));
    image.SavePNG("test.png");
}

I'm seeing valid rgb image data. Maybe you're doing something different that we're not expecting?

<save enabled=1><path>./images</path></save> does not create valid images for me but that could be a different issue.

osrf-migration commented 6 years ago

Original comment by Andrew Somerville (Bitbucket: catskul).


In my case "save enabled=1" was producing images with the same gray values that I was getting in my application.

I don't have the development environment available to do further testing in the short term, but next time there's an opportunity I'll try again.