Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add segmentation and bounding box sensor types #592

Merged
merged 16 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion include/sdf/Sensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ namespace sdf
RGBD_CAMERA = 19,

/// \brief A thermal camera sensor
THERMAL_CAMERA = 20
THERMAL_CAMERA = 20,

/// \brief A segmentation camera sensor
SEGMENTATION_CAMERA = 21,

/// \brief A boundingbox camera sensor
BOUNDINGBOX_CAMERA = 22
};

/// \brief Information about an SDF sensor.
Expand Down
2 changes: 2 additions & 0 deletions sdf/1.9/sensor.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
altimeter,
camera,
contact,
boundingbox_camera, boundingbox,
depth_camera, depth,
force_torque,
gps,
Expand All @@ -26,6 +27,7 @@
rfid,
rfidtag,
rgbd_camera, rgbd,
segmentation_camera, segmentation,
sonar,
thermal_camera, thermal,
wireless_receiver, and
Expand Down
20 changes: 19 additions & 1 deletion src/Sensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const std::vector<std::string> sensorTypeStrs =
"wireless_transmitter",
"air_pressure",
"rgbd_camera",
"thermal_camera"
"thermal_camera",
"segmentation_camera",
"boundingbox_camera"
};

class sdf::Sensor::Implementation
Expand Down Expand Up @@ -155,6 +157,8 @@ bool Sensor::operator==(const Sensor &_sensor) const
case SensorType::DEPTH_CAMERA:
case SensorType::RGBD_CAMERA:
case SensorType::THERMAL_CAMERA:
case SensorType::SEGMENTATION_CAMERA:
case SensorType::BOUNDINGBOX_CAMERA:
return *(this->dataPtr->camera) == *(_sensor.dataPtr->camera);
case SensorType::LIDAR:
return *(this->dataPtr->lidar) == *(_sensor.dataPtr->lidar);
Expand Down Expand Up @@ -266,6 +270,20 @@ Errors Sensor::Load(ElementPtr _sdf)
Errors err = this->dataPtr->camera->Load(_sdf->GetElement("camera"));
errors.insert(errors.end(), err.begin(), err.end());
}
else if (type == "segmentation" || type == "segmentation_camera")
{
this->dataPtr->type = SensorType::SEGMENTATION_CAMERA;
this->dataPtr->camera.emplace();
Errors err = this->dataPtr->camera->Load(_sdf->GetElement("camera"));
errors.insert(errors.end(), err.begin(), err.end());
}
else if (type == "boundingbox" || type == "boundingbox_camera")
{
this->dataPtr->type = SensorType::BOUNDINGBOX_CAMERA;
this->dataPtr->camera.emplace();
Errors err = this->dataPtr->camera->Load(_sdf->GetElement("camera"));
errors.insert(errors.end(), err.begin(), err.end());
}
else if (type == "force_torque")
{
this->dataPtr->type = SensorType::FORCE_TORQUE;
Expand Down
4 changes: 4 additions & 0 deletions src/Sensor_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ TEST(DOMSensor, Type)
sdf::SensorType::NONE,
sdf::SensorType::ALTIMETER,
sdf::SensorType::CAMERA,
sdf::SensorType::BOUNDINGBOX_CAMERA,
sdf::SensorType::CONTACT,
sdf::SensorType::DEPTH_CAMERA,
sdf::SensorType::FORCE_TORQUE,
Expand All @@ -256,6 +257,7 @@ TEST(DOMSensor, Type)
sdf::SensorType::LIDAR,
sdf::SensorType::RFID,
sdf::SensorType::RFIDTAG,
sdf::SensorType::SEGMENTATION_CAMERA,
sdf::SensorType::SONAR,
sdf::SensorType::WIRELESS_RECEIVER,
sdf::SensorType::WIRELESS_TRANSMITTER,
Expand All @@ -265,6 +267,7 @@ TEST(DOMSensor, Type)
{
"none",
"altimeter",
"boundingbox_camera",
"camera",
"contact",
"depth_camera",
Expand All @@ -278,6 +281,7 @@ TEST(DOMSensor, Type)
"lidar",
"rfid",
"rfidtag",
"segmentation_camera",
"sonar",
"wireless_receiver",
"wireless_transmitter",
Expand Down
26 changes: 25 additions & 1 deletion test/integration/link_dom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ TEST(DOMLink, Sensors)
const sdf::Link *link = model->LinkByIndex(0);
ASSERT_NE(nullptr, link);
EXPECT_EQ("link", link->Name());
EXPECT_EQ(22u, link->SensorCount());
EXPECT_EQ(24u, link->SensorCount());

// Get the altimeter sensor
const sdf::Sensor *altimeterSensor = link->SensorByIndex(0);
Expand Down Expand Up @@ -345,6 +345,30 @@ TEST(DOMLink, Sensors)
ASSERT_NE(nullptr, thermalCamSensor);
EXPECT_EQ("my_thermal_camera", thermalCamSensor->Name());

// Get the segmentation sensor
const sdf::Sensor *segmentationSensor =
link->SensorByName("segmentation_sensor");
ASSERT_NE(nullptr, segmentationSensor);
EXPECT_EQ("segmentation_sensor", segmentationSensor->Name());
EXPECT_EQ(sdf::SensorType::SEGMENTATION_CAMERA, segmentationSensor->Type());
EXPECT_EQ(ignition::math::Pose3d(37, 38, 39, 0, 0, 0),
segmentationSensor->RawPose());
const sdf::Camera *segmentationCameraSensor =
segmentationSensor->CameraSensor();
ASSERT_NE(nullptr, segmentationCameraSensor);
EXPECT_EQ("my_segmentation_camera", segmentationCameraSensor->Name());

// Get the boundingbox sensor
const sdf::Sensor *boundingboxSensor = link->SensorByName("boundingbox_sensor");
ASSERT_NE(nullptr, boundingboxSensor);
EXPECT_EQ("boundingbox_sensor", boundingboxSensor->Name());
EXPECT_EQ(sdf::SensorType::BOUNDINGBOX_CAMERA, boundingboxSensor->Type());
EXPECT_EQ(ignition::math::Pose3d(37, 38, 39, 0, 0, 0),
boundingboxSensor->RawPose());
const sdf::Camera *boundingboxCamSensor = boundingboxSensor->CameraSensor();
ASSERT_NE(nullptr, boundingboxCamSensor);
EXPECT_EQ("my_boundingbox_camera", boundingboxCamSensor->Name());

// Get the force_torque sensor
const sdf::Sensor *forceTorqueSensor =
link->SensorByName("force_torque_sensor");
Expand Down
117 changes: 116 additions & 1 deletion test/sdf/sensors.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
</lidar>
</sensor>


<sensor name="rfid_sensor" type="rfid">
<pose>4 5 6 0 0 0</pose>
</sensor>
Expand Down Expand Up @@ -435,6 +435,121 @@

</sensor>

<sensor name="segmentation_sensor" type="segmentation">
<pose>37 38 39 0 0 0</pose>
<camera name="my_segmentation_camera">
<pose>0.1 0.2 0.3 0 0 0</pose>
<horizontal_fov>.75</horizontal_fov>
<image>
<width>640</width>
<height>480</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.2</near>
<far>12.3</far>
</clip>

<save enabled="true">
<path>/tmp/cam</path>
</save>

<noise>
<type>gaussian</type>
<mean>0.5</mean>
<stddev>0.1</stddev>
</noise>

<distortion>
<k1>0.1</k1>
<k2>0.2</k2>
<k3>0.3</k3>
<p1>0.4</p1>
<p2>0.5</p2>
<center>0.2 0.4</center>
</distortion>
<lens>
<type>custom</type>
<scale_to_hfov>false</scale_to_hfov>
<custom_function>
<c1>1.1</c1>
<c2>2.2</c2>
<c3>3.3</c3>
<f>1.2</f>
<fun>sin</fun>
</custom_function>
<cutoff_angle>0.7505</cutoff_angle>
<env_texture_size>128</env_texture_size>
<intrinsics>
<fx>280</fx>
<fy>281</fy>
<cx>162</cx>
<cy>124</cy>
<s>1.2</s>
</intrinsics>
</lens>
</camera>

</sensor>

<sensor name="boundingbox_sensor" type="boundingbox">
<pose>37 38 39 0 0 0</pose>
<camera name="my_boundingbox_camera">
<pose>0.1 0.2 0.3 0 0 0</pose>
<horizontal_fov>.75</horizontal_fov>
<image>
<width>640</width>
<height>480</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.2</near>
<far>12.3</far>
</clip>

<save enabled="true">
<path>/tmp/cam</path>
</save>

<noise>
<type>gaussian</type>
<mean>0.5</mean>
<stddev>0.1</stddev>
</noise>

<distortion>
<k1>0.1</k1>
<k2>0.2</k2>
<k3>0.3</k3>
<p1>0.4</p1>
<p2>0.5</p2>
<center>0.2 0.4</center>
</distortion>
<lens>
<type>custom</type>
<scale_to_hfov>false</scale_to_hfov>
<custom_function>
<c1>1.1</c1>
<c2>2.2</c2>
<c3>3.3</c3>
<f>1.2</f>
<fun>sin</fun>
</custom_function>
<cutoff_angle>0.7505</cutoff_angle>
<env_texture_size>128</env_texture_size>
<intrinsics>
<fx>280</fx>
<fy>281</fy>
<cx>162</cx>
<cy>124</cy>
<s>1.2</s>
</intrinsics>
</lens>
</camera>

</sensor>


<sensor name="wireless_receiver" type="wireless_receiver">
<pose>13 14 15 0 0 0</pose>
</sensor>
Expand Down