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
44namespace visionx
45{
46 /**
47 * @class IntelRealSenseProviderPropertyDefinitions
48 * @brief
49 */
52 {
53 public:
56 {
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
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.");
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
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
constexpr T c
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.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
The CapturingPointCloudProvider provides a callback function to trigger the capturing of point clouds...
ImageProvider abstract class defines a component which provide images via ice or shared memory.
Brief description of class IntelRealSenseProvider.
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
void onInitComponent() override
Pure virtual hook for the subclass.
visionx::StereoCalibration createStereoCalibration(const rs2::pipeline_profile &selection) const
bool doCapture() override
Main capturing function.
void onExitCapturingPointCloudProvider() override
This is called when the Component::onExitComponent() setup is called.
void onDisconnectComponent() override
Hook for subclass.
void onStopCapture()
This is called when the point cloud provider capturing has been stopped.
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onStartCapture(float framesPerSecond)
This is called when the point cloud provider capturing has been started.
void onInitCapturingPointCloudProvider() override
This is called when the Component::onInitComponent() is called.
void onConnectComponent() override
Pure virtual hook for the subclass.
MetaPointCloudFormatPtr getDefaultPointCloudFormat()
default point cloud format used to initialize shared memory
void onInitImageProvider() override
This is called when the Component::onInitComponent() is called.
void onExitImageProvider() override
This is called when the Component::onExitComponent() setup is called.
virtual std::string getDefaultName() const override
bool getImagesAreUndistorted(const ::Ice::Current &c=Ice::emptyCurrent) override
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.
std::unique_ptr< CByteImage > CByteImageUPtr