IntelRealSenseProvider.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package VisionX::ArmarXObjects::IntelRealSenseProvider
17  * @author Simon Thelen ( urday at student dot kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #ifndef _ARMARX_COMPONENT_VisionX_IntelRealSenseProvider_H
24 #define _ARMARX_COMPONENT_VisionX_IntelRealSenseProvider_H
25 
26 
27 #include <Eigen/Core>
28 
29 #include <opencv2/opencv.hpp>
30 
32 #include <ArmarXCore/interface/observers/ObserverInterface.h>
33 
34 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
35 
39 #include <VisionX/interface/components/RGBDImageProvider.h>
40 
41 #include <librealsense2/h/rs_option.h>
42 #include <librealsense2/rs.hpp>
43 
44 namespace visionx
45 {
46  /**
47  * @class IntelRealSenseProviderPropertyDefinitions
48  * @brief
49  */
52  {
53  public:
56  {
57  defineOptionalProperty<Eigen::Vector2i>(
58  "Resolution", Eigen::Vector2i(1280, 720), "Resolution of the RGB and depth image.")
59  .map("424x240", Eigen::Vector2i(424, 240))
60  .map("480x270", Eigen::Vector2i(480, 270))
61  .map("640x360", Eigen::Vector2i(640, 360))
62  .map("640x480", Eigen::Vector2i(640, 480))
63  .map("848x480", Eigen::Vector2i(848, 480))
64  .map("960x540", Eigen::Vector2i(960, 540))
65  .map("1280x720", Eigen::Vector2i(1280, 720));
66 
67  defineOptionalPropertyVector("FieldOfView",
68  Eigen::Vector2f(69.4, 42.5),
69  "The horizontal and vertical field of view.");
70 
71  defineOptionalProperty<std::string>(
72  "ConfigFile",
73  "",
74  "JSON config file (e.g. from the realsense-viewer) to load. If property is not "
75  "set, the preset property is used.");
76  defineOptionalProperty<rs2_rs400_visual_preset>(
77  "Preset",
78  RS2_RS400_VISUAL_PRESET_MEDIUM_DENSITY,
79  "RealSense preset. Only used if ConfigFile property is not set.")
80  .setCaseInsensitive(true)
81  .map("CUSTOM", RS2_RS400_VISUAL_PRESET_CUSTOM)
82  .map("DEFAULT", RS2_RS400_VISUAL_PRESET_DEFAULT)
83  .map("HAND", RS2_RS400_VISUAL_PRESET_HAND)
84  .map("HIGH_ACCURACY", RS2_RS400_VISUAL_PRESET_HIGH_ACCURACY)
85  .map("HIGH_DENSITY", RS2_RS400_VISUAL_PRESET_HIGH_DENSITY)
86  .map("MEDIUM_DENSITY", RS2_RS400_VISUAL_PRESET_MEDIUM_DENSITY)
87  .map("REMOVE_IR_PATTERN", RS2_RS400_VISUAL_PRESET_REMOVE_IR_PATTERN);
88 
89  defineOptionalProperty<float>(
90  "MaxDepth",
91  6000.0f,
92  "Max depth values allowed in Millimeters. Values above these are set to nan.",
94  defineOptionalProperty<bool>("ApplySpatialFilter",
95  false,
96  "Apply a spatial filter to the depth image.",
98  defineOptionalProperty<bool>("ApplyAlignmentFilter",
99  true,
100  "Align the depth image with the rgb image.",
102  defineOptionalProperty<bool>("ApplyTemporalFilter",
103  false,
104  "Apply a temporal filter that smoothes over several "
105  "frames. Leads to artifacts in combination with motion.",
107  defineOptionalProperty<bool>("ApplyDisparityFilter",
108  true,
109  "Apply the disparity transformation filter.",
111  }
112  };
113 
114  /**
115  * @defgroup Component-IntelRealSenseProvider IntelRealSenseProvider
116  * @ingroup VisionX-Components
117  * Provides support for Intel RealSense cameras for ArmarX.
118  *
119  * @class IntelRealSenseProvider
120  * @ingroup Component-IntelRealSenseProvider
121  * @brief Brief description of class IntelRealSenseProvider.
122  *
123  *
124  */
126  virtual public visionx::RGBDPointCloudProviderInterface,
128  virtual public visionx::ImageProvider
129  {
130  public:
131  /**
132  * @see armarx::ManagedIceObject::getDefaultName()
133  */
134  virtual std::string getDefaultName() const override;
135 
136  protected:
137  /**
138  * @see PropertyUser::createPropertyDefinitions()
139  */
141 
142 
143  // ManagedIceObject interface
144  protected:
145  void onInitComponent() override;
146  void onConnectComponent() override;
147  void onDisconnectComponent() override;
148 
149  void onExitComponent();
150 
151  // StereoCalibrationInterface interface
152  public:
153  visionx::StereoCalibration
154  getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override;
155  bool getImagesAreUndistorted(const ::Ice::Current& c = Ice::emptyCurrent) override;
156 
157  std::string getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override;
158 
159  visionx::StereoCalibration
160  createStereoCalibration(const rs2::pipeline_profile& selection) const;
161 
162  protected:
163  void onStartCapture(float framesPerSecond);
164  void onStopCapture();
165  void onInitImageProvider() override;
166 
167  void
169  {
170  }
171 
172  void onInitCapturingPointCloudProvider() override;
173  void onExitCapturingPointCloudProvider() override;
174  bool doCapture() override;
175 
176  bool
177  hasSharedMemorySupport(const Ice::Current& c = Ice::emptyCurrent) override
178  {
179  return true;
180  }
181 
182  MetaPointCloudFormatPtr
184  {
185  MetaPointCloudFormatPtr info = new MetaPointCloudFormat();
186  //info->frameId = getProperty<std::string>("frameId").getValue();
187  info->type = PointContentType::eColoredPoints;
188  info->capacity = 1280 * 720 * sizeof(ColoredPoint3D); // + info->frameId.size();
189  info->size = info->capacity;
190  return info;
191  }
192 
193  private:
194  rs2::pipeline pipe;
195  rs2::colorizer color_map;
196  visionx::CByteImageUPtr depthImage;
197  using CloudPointType = pcl::PointXYZRGBA;
198  pcl::PointCloud<CloudPointType>::Ptr pointcloud;
199  armarx::DepthImageUtils depthUtils;
200  MetaPointCloudFormatPtr cloudFormat;
201 
202  visionx::StereoCalibration calibration;
203 
204  // Declare pointcloud object, for calculating pointclouds and texture mappings
205  rs2::pointcloud pc;
206  // We want the points object to be persistent so we can display the last cloud when a frame drops
207  rs2::points points;
208 
209  rs2::spatial_filter spat_filter;
210  std::unique_ptr<rs2::align> alignFilter;
211  rs2::temporal_filter temporal_filter;
212  rs2::disparity_transform depth_to_disparity_filter,
213  disparity_to_depth_filter = rs2::disparity_transform(false);
214 
215  float depthScale = 1;
216  };
217 } // namespace visionx
218 
219 #endif
visionx::IntelRealSenseProvider
Brief description of class IntelRealSenseProvider.
Definition: IntelRealSenseProvider.h:125
visionx::IntelRealSenseProvider::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: IntelRealSenseProvider.cpp:333
CapturingPointCloudProvider.h
visionx::IntelRealSenseProvider::getDefaultPointCloudFormat
MetaPointCloudFormatPtr getDefaultPointCloudFormat()
default point cloud format used to initialize shared memory
Definition: IntelRealSenseProvider.h:183
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::IntelRealSenseProvider::onExitImageProvider
void onExitImageProvider() override
This is called when the Component::onExitComponent() setup is called.
Definition: IntelRealSenseProvider.h:168
visionx::IntelRealSenseProvider::onStopCapture
void onStopCapture()
This is called when the point cloud provider capturing has been stopped.
Definition: IntelRealSenseProvider.cpp:147
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
visionx::IntelRealSenseProviderPropertyDefinitions::IntelRealSenseProviderPropertyDefinitions
IntelRealSenseProviderPropertyDefinitions(std::string prefix)
Definition: IntelRealSenseProvider.h:54
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
visionx::IntelRealSenseProvider::onExitComponent
void onExitComponent()
Hook for subclass.
Definition: IntelRealSenseProvider.cpp:357
visionx::IntelRealSenseProviderPropertyDefinitions
Definition: IntelRealSenseProvider.h:50
visionx::IntelRealSenseProvider::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: IntelRealSenseProvider.cpp:326
visionx::IntelRealSenseProvider::getImagesAreUndistorted
bool getImagesAreUndistorted(const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: IntelRealSenseProvider.cpp:370
visionx::IntelRealSenseProvider::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
Definition: IntelRealSenseProvider.cpp:376
visionx::CByteImageUPtr
std::unique_ptr< CByteImage > CByteImageUPtr
Definition: ImageProvider.h:56
armarx::DepthImageUtils
Definition: DepthImageUtils.h:15
visionx::CapturingPointCloudProviderPropertyDefinitions
Definition: CapturingPointCloudProvider.h:39
visionx::IntelRealSenseProvider::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: IntelRealSenseProvider.cpp:340
visionx::IntelRealSenseProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
Definition: IntelRealSenseProvider.h:177
Component.h
visionx::CapturingPointCloudProvider
The CapturingPointCloudProvider provides a callback function to trigger the capturing of point clouds...
Definition: CapturingPointCloudProvider.h:58
visionx::ImageProvider
ImageProvider abstract class defines a component which provide images via ice or shared memory.
Definition: ImageProvider.h:66
CapturingImageProvider.h
visionx::IntelRealSenseProvider::onStartCapture
void onStartCapture(float framesPerSecond)
This is called when the point cloud provider capturing has been started.
Definition: IntelRealSenseProvider.cpp:72
armarx::PropertyDefinitionContainer::defineOptionalPropertyVector
PropertyDefinition< EigenVectorType > & defineOptionalPropertyVector(const std::string &name, EigenVectorType defaultValue, const std::string &description="", const std::string &delimiter=" ", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Define a required property for an Eigen vector type.
Definition: PropertyDefinitionContainer.h:573
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::IntelRealSenseProvider::createStereoCalibration
visionx::StereoCalibration createStereoCalibration(const rs2::pipeline_profile &selection) const
Definition: IntelRealSenseProvider.cpp:382
DepthImageUtils.h
visionx::IntelRealSenseProvider::getDefaultName
virtual std::string getDefaultName() const override
Definition: IntelRealSenseProvider.cpp:320
visionx::IntelRealSenseProvider::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: IntelRealSenseProvider.cpp:348
visionx::IntelRealSenseProvider::onInitImageProvider
void onInitImageProvider() override
This is called when the Component::onInitComponent() is called.
Definition: IntelRealSenseProvider.cpp:46
armarx::PropertyDefinitionBase::eModifiable
@ eModifiable
Definition: PropertyDefinitionInterface.h:57
visionx::IntelRealSenseProvider::onExitCapturingPointCloudProvider
void onExitCapturingPointCloudProvider() override
This is called when the Component::onExitComponent() setup is called.
Definition: IntelRealSenseProvider.cpp:67
visionx::IntelRealSenseProvider::doCapture
bool doCapture() override
Main capturing function.
Definition: IntelRealSenseProvider.cpp:153
visionx::IntelRealSenseProvider::onInitCapturingPointCloudProvider
void onInitCapturingPointCloudProvider() override
This is called when the Component::onInitComponent() is called.
Definition: IntelRealSenseProvider.cpp:62
visionx::IntelRealSenseProvider::getStereoCalibration
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Definition: IntelRealSenseProvider.cpp:364