Skip to content

Commit fb97d96

Browse files
AmrElsersyadlarkinchapulina
authored
Segmentation Sensor (#133)
Signed-off-by: AmrElsersy <[email protected]> Signed-off-by: Ashton Larkin <[email protected]> Co-authored-by: Ashton Larkin <[email protected]> Co-authored-by: Louise Poubel <[email protected]>
1 parent e99a8bc commit fb97d96

14 files changed

+1626
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright (C) 2021 Open Source Robotics Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
#ifndef IGNITION_SENSORS_SEGMENTATIONCAMERASENSOR_HH_
19+
#define IGNITION_SENSORS_SEGMENTATIONCAMERASENSOR_HH_
20+
21+
#include <memory>
22+
#include <string>
23+
24+
#include <ignition/common/Event.hh>
25+
#include <ignition/common/PluginMacros.hh>
26+
#include <ignition/common/SuppressWarning.hh>
27+
#include <ignition/common/Time.hh>
28+
#include <ignition/msgs.hh>
29+
#include <ignition/transport/Node.hh>
30+
#include <ignition/transport/Publisher.hh>
31+
#include <sdf/sdf.hh>
32+
33+
#include "ignition/sensors/CameraSensor.hh"
34+
#include "ignition/sensors/Export.hh"
35+
#include "ignition/sensors/Sensor.hh"
36+
37+
#include "ignition/sensors/segmentation_camera/Export.hh"
38+
39+
namespace ignition
40+
{
41+
namespace sensors
42+
{
43+
// Inline bracket to help doxygen filtering.
44+
inline namespace IGNITION_SENSORS_VERSION_NAMESPACE {
45+
// forward declarations
46+
class SegmentationCameraSensorPrivate;
47+
48+
/// \brief Segmentation camera sensor class.
49+
///
50+
/// This class creates segmentation images from an ignition rendering scene.
51+
/// The scene must be created in advance and given to Manager::Init().
52+
/// It offers both an ignition-transport interface and a direct C++ API
53+
/// to access the image data. The API works by setting a callback to be
54+
/// called with image data.
55+
class IGNITION_SENSORS_SEGMENTATION_CAMERA_VISIBLE
56+
SegmentationCameraSensor : public CameraSensor
57+
{
58+
/// \brief constructor
59+
public: SegmentationCameraSensor();
60+
61+
/// \brief destructor
62+
public: virtual ~SegmentationCameraSensor();
63+
64+
/// \brief Load the sensor based on data from an sdf::Sensor object.
65+
/// \param[in] _sdf SDF Sensor parameters.
66+
/// \return true if loading was successful
67+
public: virtual bool Load(const sdf::Sensor &_sdf) override;
68+
69+
/// \brief Load the sensor with SDF parameters.
70+
/// \param[in] _sdf SDF Sensor parameters.
71+
/// \return true if loading was successful
72+
public: virtual bool Load(sdf::ElementPtr _sdf) override;
73+
74+
/// \brief Initialize values in the sensor
75+
/// \return True on success
76+
public: virtual bool Init() override;
77+
78+
/// \brief Force the sensor to generate data
79+
/// \param[in] _now The current time
80+
/// \return true if the update was successful
81+
public: virtual bool Update(
82+
const std::chrono::steady_clock::duration &_now) override;
83+
84+
/// \brief Get the rendering segmentation camera
85+
/// \return Segmentation camera pointer
86+
public: rendering::SegmentationCameraPtr SegmentationCamera() const;
87+
88+
/// \brief Segmentation data callback used to get the data from the sensor
89+
/// \param[in] _data pointer to the data from the sensor
90+
/// \param[in] _width width of the segmentation image
91+
/// \param[in] _height height of the segmentation image
92+
/// \param[in] _channels num of channels
93+
/// \param[in] _format string with the format
94+
public: void OnNewSegmentationFrame(const uint8_t * _data,
95+
unsigned int _width, unsigned int _height, unsigned int _channels,
96+
const std::string &_format);
97+
98+
/// \brief Set a callback to be called when image frame data is
99+
/// generated.
100+
/// \param[in] _callback This callback will be called every time the
101+
/// camera produces image data. The Update function will be blocked
102+
/// while the callbacks are executed.
103+
/// \remark Do not block inside of the callback.
104+
/// \return A connection pointer that must remain in scope. When the
105+
/// connection pointer falls out of scope, the connection is broken.
106+
public: ignition::common::ConnectionPtr ConnectImageCallback(
107+
std::function<void(const ignition::msgs::Image &)> _callback);
108+
109+
/// \brief Set the rendering scene.
110+
/// \param[in] _scene Pointer to the scene
111+
public: virtual void SetScene(
112+
ignition::rendering::ScenePtr _scene) override;
113+
114+
/// \brief Get image width.
115+
/// \return width of the image
116+
public: virtual unsigned int ImageWidth() const override;
117+
118+
/// \brief Get image height.
119+
/// \return height of the image
120+
public: virtual unsigned int ImageHeight() const override;
121+
122+
/// \brief Create a camera in a scene
123+
/// \return True on success.
124+
private: bool CreateCamera();
125+
126+
IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
127+
/// \brief Data pointer for private data
128+
/// \internal
129+
private: std::unique_ptr<SegmentationCameraSensorPrivate> dataPtr;
130+
IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
131+
};
132+
}
133+
}
134+
}
135+
136+
#endif

src/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ target_link_libraries(${thermal_camera_target}
136136
ignition-transport${IGN_TRANSPORT_VER}::ignition-transport${IGN_TRANSPORT_VER}
137137
)
138138

139+
set(segmentation_camera_sources SegmentationCameraSensor.cc)
140+
ign_add_component(segmentation_camera SOURCES ${segmentation_camera_sources} GET_TARGET_NAME segmentation_camera_target)
141+
target_compile_definitions(${segmentation_camera_target} PUBLIC SegmentationCameraSensor_EXPORTS)
142+
target_link_libraries(${segmentation_camera_target}
143+
PRIVATE
144+
${camera_target}
145+
ignition-msgs${IGN_MSGS_VER}::ignition-msgs${IGN_MSGS_VER}
146+
ignition-transport${IGN_TRANSPORT_VER}::ignition-transport${IGN_TRANSPORT_VER}
147+
)
148+
139149
# Build the unit tests.
140150
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} LIB_DEPS ${rendering_target})
141151

0 commit comments

Comments
 (0)