Skip to content

Commit 1f99c07

Browse files
peci1mergify[bot]
authored andcommitted
fix(thermal_camera): Fixed Gaussian noise for thermal camera. (#597)
Signed-off-by: Martin Pecka <peci1@seznam.cz> (cherry picked from commit 0e561e3)
1 parent 5e2fba3 commit 1f99c07

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

src/ThermalCameraSensor.cc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#include "gz/sensors/ThermalCameraSensor.hh"
4242
#include "gz/sensors/ImageGaussianNoiseModel.hh"
43+
#include "gz/sensors/ImageNoise.hh"
4344
#include "gz/sensors/RenderingEvents.hh"
4445
#include "gz/sensors/SensorFactory.hh"
4546

@@ -317,12 +318,20 @@ bool ThermalCameraSensor::CreateCamera()
317318
// Add gaussian noise to camera sensor
318319
if (noiseSdf.Type() == sdf::NoiseType::GAUSSIAN)
319320
{
320-
this->dataPtr->noises[noiseType] =
321-
NoiseFactory::NewNoiseModel(noiseSdf, "camera");
321+
// Skip applying noise if mean and stddev are 0 - this avoids
322+
// doing an extra render pass in gz-rendering
323+
// Note ImageGaussianNoiseModel only uses mean and stddev and does not
324+
// use bias parameters.
325+
if (!math::equal(noiseSdf.Mean(), 0.0) ||
326+
!math::equal(noiseSdf.StdDev(), 0.0))
327+
{
328+
this->dataPtr->noises[noiseType] =
329+
ImageNoiseFactory::NewNoiseModel(noiseSdf, "thermal_camera");
322330

323-
std::dynamic_pointer_cast<ImageGaussianNoiseModel>(
324-
this->dataPtr->noises[noiseType])->SetCamera(
325-
this->dataPtr->thermalCamera);
331+
std::dynamic_pointer_cast<ImageGaussianNoiseModel>(
332+
this->dataPtr->noises[noiseType])->SetCamera(
333+
this->dataPtr->thermalCamera);
334+
}
326335
}
327336
else if (noiseSdf.Type() != sdf::NoiseType::NONE)
328337
{

test/integration/thermal_camera.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ void ThermalCameraSensorTest::ImagesWithBuiltinSDF(
126126
auto imagePtr = cameraPtr->GetElement("image");
127127
ASSERT_TRUE(cameraPtr->HasElement("clip"));
128128
auto clipPtr = cameraPtr->GetElement("clip");
129+
ASSERT_TRUE(cameraPtr->HasElement("noise"));
130+
auto noisePtr = cameraPtr->GetElement("noise");
131+
132+
EXPECT_EQ("gaussian", noisePtr->Get<std::string>("type"));
133+
EXPECT_FLOAT_EQ(0.0, noisePtr->Get<double>("mean"));
134+
EXPECT_DOUBLE_EQ(0.007, noisePtr->Get<double>("stddev"));
129135

130136
int imgWidth = imagePtr->Get<int>("width");
131137
int imgHeight = imagePtr->Get<int>("height");
@@ -386,6 +392,12 @@ void ThermalCameraSensorTest::Images8BitWithBuiltinSDF(
386392
auto cameraPtr = sensorPtr->GetElement("camera");
387393
ASSERT_TRUE(cameraPtr->HasElement("image"));
388394
auto imagePtr = cameraPtr->GetElement("image");
395+
ASSERT_TRUE(cameraPtr->HasElement("noise"));
396+
auto noisePtr = cameraPtr->GetElement("noise");
397+
398+
EXPECT_EQ("gaussian", noisePtr->Get<std::string>("type"));
399+
EXPECT_FLOAT_EQ(0.0, noisePtr->Get<double>("mean"));
400+
EXPECT_DOUBLE_EQ(0.007, noisePtr->Get<double>("stddev"));
389401

390402
std::string format = imagePtr->Get<std::string>("format");
391403
EXPECT_EQ("L8", format);

test/sdf/thermal_camera_sensor_8bit_builtin.sdf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
<near>0.1</near>
1717
<far>10.0</far>
1818
</clip>
19+
<noise>
20+
<type>gaussian</type>
21+
<mean>0.0</mean>
22+
<stddev>0.007</stddev>
23+
</noise>
1924
</camera>
2025
</sensor>
2126
</link>

test/sdf/thermal_camera_sensor_builtin.sdf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
<near>0.1</near>
1717
<far>10.0</far>
1818
</clip>
19+
<noise>
20+
<type>gaussian</type>
21+
<mean>0.0</mean>
22+
<stddev>0.007</stddev>
23+
</noise>
1924
</camera>
2025
</sensor>
2126
</link>

0 commit comments

Comments
 (0)