KinectV2PointCloudProvider.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package VisionX::ArmarXObjects::KinectV2PointCloudProvider
19 * @author Christoph Pohl (christoph dot pohl at kit dot edu)
20 * @date 2019
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
27
30
33#include <VisionX/interface/components/RGBDImageProvider.h>
34//#include <VisionX/interface/components/Calibration.h>
35
36#include <Eigen/Geometry>
37
38#include <pcl/common/transforms.h>
39#include <pcl/point_cloud.h>
40#include <pcl/point_types.h>
41
43
44#include <libfreenect2/frame_listener_impl.h>
45#include <libfreenect2/libfreenect2.hpp>
46#include <libfreenect2/packet_pipeline.h>
47#include <libfreenect2/registration.h>
48
49//#include <Image/IplImageAdaptor.h>
50
51namespace visionx
52{
62
63 /**
64 * @class KinectV2PointCloudProviderPropertyDefinitions
65 * @brief
66 */
69 {
70 public:
73 {
74 defineOptionalProperty<bool>("EnableRGB", true, "Enable color image.");
75 defineOptionalProperty<bool>("EnableDepth", true, "Enable depth image.");
77 "Pipeline",
78 CPU,
79 "Kinect Pipeline for image processing. Can be one of CPU, GL, CL, CLKDE, CUDA, "
80 "CUDAKDE")
81 .map("CPU", CPU)
82 .map("GL", OPENGL)
83 .map("CL", OPENCL)
84 .map("CLKDE", OPENCLKDE)
85 .map("CUDA", CUDA)
86 .map("CUDAKDE", CUDAKDE);
88 "",
89 "Serial Number of the Camera to use. If empty the "
90 "serial will be chosen automatically");
91 defineOptionalProperty<bool>("Mirror", false, "Mirrors the resulting images");
93 "ReferenceFrameName", "DepthCamera", "Optional reference frame name.");
94 }
95 };
96
97 /**
98 * @class KinectV2PointCloudProvider
99 * @ingroup VisionX-Components
100 * @brief A brief description
101 *
102 * Detailed Description
103 */
105 virtual public RGBDPointCloudProviderInterface,
106 virtual public CapturingPointCloudProvider,
107 virtual public ImageProvider
108 {
109 public:
110 /**
111 * @see armarx::ManagedIceObject::getDefaultName()
112 */
114 listener_(libfreenect2::Frame::Color | libfreenect2::Frame::Ir |
115 libfreenect2::Frame::Depth),
116 undistorted_(512, 424, 4),
117 registered_(512, 424, 4){};
118
119 std::string
120 getDefaultName() const override
121 {
122 return "KinectV2PointCloudProvider";
123 }
124
125 protected:
126 /**
127 * @see visionx::PointCloudProviderBase::onInitPointCloudProvider()
128 */
129 void onInitCapturingPointCloudProvider() override;
130
131 /**
132 * @see visionx::PointCloudProviderBase::onExitPointCloudProvider()
133 */
134 void onExitCapturingPointCloudProvider() override;
135
136 /**
137 * @see visionx::PointCloudProviderBase::onStartCapture()
138 */
139 void onStartCapture(float frameRate) override;
140
141 /**
142 * @see visionx::PointCloudProviderBase::onStopCapture()
143 */
144 void onStopCapture() override;
145
146 /**
147 * @see visionx::PointCloudProviderBase::doCapture()
148 */
149 bool doCapture() override;
150
151 /**
152 * @see visionx::CapturingImageProvider::onInitImageProvider()
153 */
154 void onInitImageProvider() override;
155
156 /**
157 * @see visionx::CapturingImageProvider::onExitImageProvider()
158 */
159 void
161 {
162 }
163
164 bool
165 hasSharedMemorySupport(const Ice::Current& c = Ice::emptyCurrent) override
166 {
167 return true;
168 }
169
170 /**
171 * @see PropertyUser::createPropertyDefinitions()
172 */
174
175 // mixed inherited stuff
176 void onInitComponent() override;
177
178 void onConnectComponent() override;
179
180 void onDisconnectComponent() override;
181
182 void onExitComponent() override;
183
184 StereoCalibration getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override;
185
186 bool
187 getImagesAreUndistorted(const ::Ice::Current& c = Ice::emptyCurrent) override
188 {
189 return false;
190 }
191
192 std::string
193 getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override
194 {
195 return getProperty<std::string>("ReferenceFrameName");
196 };
197
198 private:
199 typedef pcl::PointXYZRGBA PointT;
200
201 libfreenect2::Freenect2Device::IrCameraParams getCameraIrParameters();
202
203 libfreenect2::Freenect2Device::ColorCameraParams getCameraRGBParameters();
204
205 void initializeCameraCalibration();
206
207 libfreenect2::Freenect2 freenect2_;
208 libfreenect2::Freenect2Device* dev_;
209 libfreenect2::PacketPipeline* pipeline_;
210 libfreenect2::SyncMultiFrameListener listener_;
211 libfreenect2::FrameMap frames_;
212 libfreenect2::Registration* registration_;
213 libfreenect2::Frame undistorted_, registered_;
214 bool enable_rgb_, enable_depth_, mirror_;
215 int deviceId_;
216 std::string serial_;
217 KinectProcessorType pipeline_type_;
218
219 KinectToPCLHelper<PointT>* pclHelper;
220 KinectToIVTHelper* ivtHelper;
221
222 ImageProviderInterfacePrx imageProviderPrx;
223 std::string providerName;
224 CByteImage** rgbImages_;
225 int rgb_width_, rgb_height_, d_width_, d_height_;
226 StereoCalibration calibration;
227 };
228} // namespace visionx
constexpr T c
Property< PropertyType > getProperty(const std::string &name)
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.
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.
void onDisconnectComponent() override
Hook for subclass.
void onConnectComponent() override
Pure virtual hook for the subclass.
StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onExitComponent() override
Hook for subclass.
std::string getDefaultName() const override
Retrieve default name of component.
bool getImagesAreUndistorted(const ::Ice::Current &c=Ice::emptyCurrent) override
uint32_t Color
RGBA color.
Definition color.h:8
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.