Skip to content

Commit

Permalink
Merge pull request #35 from ignitionrobotics/depth_noise
Browse files Browse the repository at this point in the history
Add noise to RGBD camera
  • Loading branch information
nkoenig authored Aug 7, 2020
2 parents a2b4904 + bb82bcc commit d84ef53
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Noise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ NoisePtr NoiseFactory::NewNoiseModel(const sdf::Noise &_sdf,
noiseType == sdf::NoiseType::GAUSSIAN_QUANTIZED)
{
if (_sensorType == "camera" || _sensorType == "depth" ||
_sensorType == "multicamera" || _sensorType == "wideanglecamera")
_sensorType == "multicamera" || _sensorType == "wideanglecamera" ||
_sensorType == "rgbd_camera")
{
noise.reset(new ImageGaussianNoiseModel());
}
Expand Down
28 changes: 28 additions & 0 deletions src/RgbdCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <sdf/Sensor.hh>

#include "ignition/sensors/GaussianNoiseModel.hh"
#include "ignition/sensors/RgbdCameraSensor.hh"
#include "ignition/sensors/SensorFactory.hh"

Expand Down Expand Up @@ -100,6 +101,9 @@ class ignition::sensors::RgbdCameraSensorPrivate
/// \brief Pointer to an image to be published
public: ignition::rendering::Image image;

/// \brief Noise added to sensor data
public: std::map<SensorNoiseType, NoisePtr> noises;

/// \brief Connection from depth camera with new depth data
public: ignition::common::ConnectionPtr depthConnection;

Expand Down Expand Up @@ -275,6 +279,30 @@ bool RgbdCameraSensor::CreateCameras()

this->AddSensor(this->dataPtr->depthCamera);

const std::map<SensorNoiseType, sdf::Noise> noises = {
{CAMERA_NOISE, cameraSdf->ImageNoise()},
};

for (const auto & [noiseType, noiseSdf] : noises)
{
// Add gaussian noise to camera sensor
if (noiseSdf.Type() == sdf::NoiseType::GAUSSIAN)
{
this->dataPtr->noises[noiseType] =
NoiseFactory::NewNoiseModel(noiseSdf, "rgbd_camera");

std::dynamic_pointer_cast<ImageGaussianNoiseModel>(
this->dataPtr->noises[noiseType])->SetCamera(
this->dataPtr->depthCamera);
}
else if (noiseSdf.Type() != sdf::NoiseType::NONE)
{
ignwarn << "The depth camera sensor only supports Gaussian noise. "
<< "The supplied noise type[" << static_cast<int>(noiseSdf.Type())
<< "] is not supported." << std::endl;
}
}

// \todo(nkoeng) these parameters via sdf
this->dataPtr->depthCamera->SetAntiAliasing(2);

Expand Down

0 comments on commit d84ef53

Please sign in to comment.