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 
28 
29 #include <ArmarXCore/interface/observers/ObserverInterface.h>
30 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
33 #include <VisionX/interface/components/RGBDImageProvider.h>
34 
35 #include <Eigen/Core>
36 
37 #include <opencv2/opencv.hpp>
38 
40 
41 #include <librealsense2/rs.hpp>
42 #include <librealsense2/h/rs_option.h>
43 
44 namespace visionx
45 {
46  /**
47  * @class IntelRealSenseProviderPropertyDefinitions
48  * @brief
49  */
52  {
53  public:
56  {
57  defineOptionalProperty<Eigen::Vector2i>("Resolution", Eigen::Vector2i(1280, 720), "Resolution of the RGB and depth image.")
58  .map("424x240", Eigen::Vector2i(424, 240))
59  .map("480x270", Eigen::Vector2i(480, 270))
60  .map("640x360", Eigen::Vector2i(640, 360))
61  .map("640x480", Eigen::Vector2i(640, 480))
62  .map("848x480", Eigen::Vector2i(848, 480))
63  .map("960x540", Eigen::Vector2i(960, 540))
64  .map("1280x720", Eigen::Vector2i(1280, 720));
65 
66  defineOptionalPropertyVector("FieldOfView", Eigen::Vector2f(69.4, 42.5), "The horizontal and vertical field of view.");
67 
68  defineOptionalProperty<std::string>("ConfigFile", "", "JSON config file (e.g. from the realsense-viewer) to load. If property is not set, the preset property is used.");
69  defineOptionalProperty<rs2_rs400_visual_preset>("Preset", RS2_RS400_VISUAL_PRESET_MEDIUM_DENSITY, "RealSense preset. Only used if ConfigFile property is not set.").
70  setCaseInsensitive(true).
71  map("CUSTOM", RS2_RS400_VISUAL_PRESET_CUSTOM).
72  map("DEFAULT", RS2_RS400_VISUAL_PRESET_DEFAULT).
73  map("HAND", RS2_RS400_VISUAL_PRESET_HAND).
74  map("HIGH_ACCURACY", RS2_RS400_VISUAL_PRESET_HIGH_ACCURACY).
75  map("HIGH_DENSITY", RS2_RS400_VISUAL_PRESET_HIGH_DENSITY).
76  map("MEDIUM_DENSITY", RS2_RS400_VISUAL_PRESET_MEDIUM_DENSITY).
77  map("REMOVE_IR_PATTERN", RS2_RS400_VISUAL_PRESET_REMOVE_IR_PATTERN);
78 
79  defineOptionalProperty<float>("MaxDepth", 6000.0f, "Max depth values allowed in Millimeters. Values above these are set to nan.", armarx::PropertyDefinitionBase::eModifiable);
80  defineOptionalProperty<bool>("ApplySpatialFilter", false, "Apply a spatial filter to the depth image.", armarx::PropertyDefinitionBase::eModifiable);
81  defineOptionalProperty<bool>("ApplyAlignmentFilter", true, "Align the depth image with the rgb image.", armarx::PropertyDefinitionBase::eModifiable);
82  defineOptionalProperty<bool>("ApplyTemporalFilter", false, "Apply a temporal filter that smoothes over several frames. Leads to artifacts in combination with motion.", armarx::PropertyDefinitionBase::eModifiable);
83  defineOptionalProperty<bool>("ApplyDisparityFilter", true, "Apply the disparity transformation filter.", armarx::PropertyDefinitionBase::eModifiable);
84 
85  }
86  };
87 
88  /**
89  * @defgroup Component-IntelRealSenseProvider IntelRealSenseProvider
90  * @ingroup VisionX-Components
91  * Provides support for Intel RealSense cameras for ArmarX.
92  *
93  * @class IntelRealSenseProvider
94  * @ingroup Component-IntelRealSenseProvider
95  * @brief Brief description of class IntelRealSenseProvider.
96  *
97  *
98  */
100  virtual public visionx::RGBDPointCloudProviderInterface,
102  virtual public visionx::ImageProvider
103  {
104  public:
105  /**
106  * @see armarx::ManagedIceObject::getDefaultName()
107  */
108  virtual std::string getDefaultName() const override;
109 
110  protected:
111 
112 
113 
114 
115  /**
116  * @see PropertyUser::createPropertyDefinitions()
117  */
119 
120 
121 
122  // ManagedIceObject interface
123  protected:
124  void onInitComponent() override;
125  void onConnectComponent() override;
126  void onDisconnectComponent() override;
127 
128  void onExitComponent();
129 
130  // StereoCalibrationInterface interface
131  public:
132  visionx::StereoCalibration getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override;
133  bool getImagesAreUndistorted(const ::Ice::Current& c = Ice::emptyCurrent) override;
134 
135  std::string getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override;
136 
137  visionx::StereoCalibration createStereoCalibration(const rs2::pipeline_profile& selection) const;
138 
139  protected:
140  void onStartCapture(float framesPerSecond);
141  void onStopCapture();
142  void onInitImageProvider() override;
143  void onExitImageProvider() override {}
144 
145  void onInitCapturingPointCloudProvider() override;
146  void onExitCapturingPointCloudProvider() override;
147  bool doCapture() override;
148  bool hasSharedMemorySupport(const Ice::Current& c = Ice::emptyCurrent) override
149  {
150  return true;
151  }
152  MetaPointCloudFormatPtr getDefaultPointCloudFormat()
153  {
154  MetaPointCloudFormatPtr info = new MetaPointCloudFormat();
155  //info->frameId = getProperty<std::string>("frameId").getValue();
156  info->type = PointContentType::eColoredPoints;
157  info->capacity = 1280 * 720 * sizeof(ColoredPoint3D);// + info->frameId.size();
158  info->size = info->capacity;
159  return info;
160  }
161  private:
162 
163 
164  rs2::pipeline pipe;
165  rs2::colorizer color_map;
166  visionx::CByteImageUPtr depthImage;
167  using CloudPointType = pcl::PointXYZRGBA;
168  pcl::PointCloud<CloudPointType>::Ptr pointcloud;
169  armarx::DepthImageUtils depthUtils;
170  MetaPointCloudFormatPtr cloudFormat;
171 
172  visionx::StereoCalibration calibration;
173 
174  // Declare pointcloud object, for calculating pointclouds and texture mappings
175  rs2::pointcloud pc;
176  // We want the points object to be persistent so we can display the last cloud when a frame drops
177  rs2::points points;
178 
179  rs2::spatial_filter spat_filter;
180  std::unique_ptr<rs2::align> alignFilter;
181  rs2::temporal_filter temporal_filter;
182  rs2::disparity_transform depth_to_disparity_filter, disparity_to_depth_filter = rs2::disparity_transform(false);
183 
184  float depthScale = 1;
185 
186  };
187 }
188 
189 #endif
visionx::IntelRealSenseProvider
Brief description of class IntelRealSenseProvider.
Definition: IntelRealSenseProvider.h:99
visionx::IntelRealSenseProvider::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: IntelRealSenseProvider.cpp:328
CapturingPointCloudProvider.h
visionx::IntelRealSenseProvider::getDefaultPointCloudFormat
MetaPointCloudFormatPtr getDefaultPointCloudFormat()
default point cloud format used to initialize shared memory
Definition: IntelRealSenseProvider.h:152
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:143
visionx::IntelRealSenseProvider::onStopCapture
void onStopCapture()
This is called when the point cloud provider capturing has been stopped.
Definition: IntelRealSenseProvider.cpp:142
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
visionx::IntelRealSenseProviderPropertyDefinitions::IntelRealSenseProviderPropertyDefinitions
IntelRealSenseProviderPropertyDefinitions(std::string prefix)
Definition: IntelRealSenseProvider.h:54
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::IntelRealSenseProvider::onExitComponent
void onExitComponent()
Hook for subclass.
Definition: IntelRealSenseProvider.cpp:349
visionx::IntelRealSenseProviderPropertyDefinitions
Definition: IntelRealSenseProvider.h:50
visionx::IntelRealSenseProvider::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: IntelRealSenseProvider.cpp:322
visionx::IntelRealSenseProvider::getImagesAreUndistorted
bool getImagesAreUndistorted(const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: IntelRealSenseProvider.cpp:361
visionx::IntelRealSenseProvider::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
Definition: IntelRealSenseProvider.cpp:366
visionx::CByteImageUPtr
std::unique_ptr< CByteImage > CByteImageUPtr
Definition: ImageProvider.h:57
armarx::DepthImageUtils
Definition: DepthImageUtils.h:12
visionx::CapturingPointCloudProviderPropertyDefinitions
Definition: CapturingPointCloudProvider.h:38
visionx::IntelRealSenseProvider::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: IntelRealSenseProvider.cpp:334
visionx::IntelRealSenseProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
Definition: IntelRealSenseProvider.h:148
Component.h
visionx::CapturingPointCloudProvider
The CapturingPointCloudProvider provides a callback function to trigger the capturing of point clouds...
Definition: CapturingPointCloudProvider.h:56
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:68
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:581
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::IntelRealSenseProvider::createStereoCalibration
visionx::StereoCalibration createStereoCalibration(const rs2::pipeline_profile &selection) const
Definition: IntelRealSenseProvider.cpp:371
DepthImageUtils.h
visionx::IntelRealSenseProvider::getDefaultName
virtual std::string getDefaultName() const override
Definition: IntelRealSenseProvider.cpp:317
visionx::IntelRealSenseProvider::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: IntelRealSenseProvider.cpp:341
visionx::IntelRealSenseProvider::onInitImageProvider
void onInitImageProvider() override
This is called when the Component::onInitComponent() is called.
Definition: IntelRealSenseProvider.cpp:45
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:62
visionx::IntelRealSenseProvider::doCapture
bool doCapture() override
Main capturing function.
Definition: IntelRealSenseProvider.cpp:149
visionx::IntelRealSenseProvider::onInitCapturingPointCloudProvider
void onInitCapturingPointCloudProvider() override
This is called when the Component::onInitComponent() is called.
Definition: IntelRealSenseProvider.cpp:58
visionx::IntelRealSenseProvider::getStereoCalibration
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Definition: IntelRealSenseProvider.cpp:356