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 
32 
33 #include <VisionX/interface/components/RGBDImageProvider.h>
34 //#include <VisionX/interface/components/Calibration.h>
35 
36 #include <pcl/common/transforms.h>
37 #include <pcl/point_cloud.h>
38 #include <pcl/point_types.h>
39 
40 #include <libfreenect2/libfreenect2.hpp>
41 #include <libfreenect2/frame_listener_impl.h>
42 #include <libfreenect2/registration.h>
43 #include <libfreenect2/packet_pipeline.h>
44 
45 #include <Eigen/Geometry>
46 
48 
49 
50 //#include <Image/IplImageAdaptor.h>
51 
52 namespace visionx
53 {
55  {
57  };
58 
59  /**
60  * @class KinectV2PointCloudProviderPropertyDefinitions
61  * @brief
62  */
65  {
66  public:
69  {
70  defineOptionalProperty<bool>("EnableRGB", true, "Enable color image.");
71  defineOptionalProperty<bool>("EnableDepth", true, "Enable depth image.");
72  defineOptionalProperty<KinectProcessorType>("Pipeline", CPU,
73  "Kinect Pipeline for image processing. Can be one of CPU, GL, CL, CLKDE, CUDA, CUDAKDE")
74  .map("CPU", CPU)
75  .map("GL", OPENGL)
76  .map("CL", OPENCL)
77  .map("CLKDE", OPENCLKDE)
78  .map("CUDA", CUDA)
79  .map("CUDAKDE", CUDAKDE);
80  defineOptionalProperty<std::string>("Serial", "",
81  "Serial Number of the Camera to use. If empty the serial will be chosen automatically");
82  defineOptionalProperty<bool>("Mirror", false,
83  "Mirrors the resulting images");
84  defineOptionalProperty<std::string>("ReferenceFrameName", "DepthCamera", "Optional reference frame name.");
85  }
86  };
87 
88  /**
89  * @class KinectV2PointCloudProvider
90  * @ingroup VisionX-Components
91  * @brief A brief description
92  *
93  * Detailed Description
94  */
96  virtual public RGBDPointCloudProviderInterface,
97  virtual public CapturingPointCloudProvider,
98  virtual public ImageProvider
99  {
100  public:
101  /**
102  * @see armarx::ManagedIceObject::getDefaultName()
103  */
105  libfreenect2::Frame::Color | libfreenect2::Frame::Ir | libfreenect2::Frame::Depth),
106  undistorted_(512, 424, 4), registered_(512, 424, 4) {};
107 
108  std::string getDefaultName() const override
109  {
110  return "KinectV2PointCloudProvider";
111  }
112 
113  protected:
114  /**
115  * @see visionx::PointCloudProviderBase::onInitPointCloudProvider()
116  */
117  void onInitCapturingPointCloudProvider() override;
118 
119  /**
120  * @see visionx::PointCloudProviderBase::onExitPointCloudProvider()
121  */
122  void onExitCapturingPointCloudProvider() override;
123 
124  /**
125  * @see visionx::PointCloudProviderBase::onStartCapture()
126  */
127  void onStartCapture(float frameRate) override;
128 
129  /**
130  * @see visionx::PointCloudProviderBase::onStopCapture()
131  */
132  void onStopCapture() override;
133 
134  /**
135  * @see visionx::PointCloudProviderBase::doCapture()
136  */
137  bool doCapture() override;
138 
139  /**
140  * @see visionx::CapturingImageProvider::onInitImageProvider()
141  */
142  void onInitImageProvider() override;
143 
144  /**
145  * @see visionx::CapturingImageProvider::onExitImageProvider()
146  */
147  void onExitImageProvider() override {}
148 
149  bool hasSharedMemorySupport(const Ice::Current& c = Ice::emptyCurrent) override
150  {
151  return true;
152  }
153 
154  /**
155  * @see PropertyUser::createPropertyDefinitions()
156  */
158 
159  // mixed inherited stuff
160  void onInitComponent() override;
161 
162  void onConnectComponent() override;
163 
164  void onDisconnectComponent() override;
165 
166  void onExitComponent() override;
167 
168  StereoCalibration getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override;
169 
170  bool getImagesAreUndistorted(const ::Ice::Current& c = Ice::emptyCurrent) override
171  {
172  return false;
173  }
174 
175 
176  std::string getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override
177  {
178  return getProperty<std::string>("ReferenceFrameName");
179  };
180 
181  private:
182  typedef pcl::PointXYZRGBA PointT;
183 
184  libfreenect2::Freenect2Device::IrCameraParams getCameraIrParameters();
185 
186  libfreenect2::Freenect2Device::ColorCameraParams getCameraRGBParameters();
187 
188  void initializeCameraCalibration();
189 
190  libfreenect2::Freenect2 freenect2_;
191  libfreenect2::Freenect2Device* dev_;
192  libfreenect2::PacketPipeline* pipeline_;
193  libfreenect2::SyncMultiFrameListener listener_;
194  libfreenect2::FrameMap frames_;
195  libfreenect2::Registration* registration_;
196  libfreenect2::Frame undistorted_, registered_;
197  bool enable_rgb_, enable_depth_, mirror_;
198  int deviceId_;
199  std::string serial_;
200  KinectProcessorType pipeline_type_;
201 
202  KinectToPCLHelper<PointT>* pclHelper;
203  KinectToIVTHelper* ivtHelper;
204 
205  ImageProviderInterfacePrx imageProviderPrx;
206  std::string providerName;
207  CByteImage** rgbImages_;
208  int rgb_width_, rgb_height_, d_width_, d_height_;
209  StereoCalibration calibration;
210 
211  };
212 }
CapturingPointCloudProvider.h
visionx::CUDA
@ CUDA
Definition: KinectV2PointCloudProvider.h:56
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::KinectV2PointCloudProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinectV2PointCloudProvider.h:149
visionx::KinectV2PointCloudProvider
A brief description.
Definition: KinectV2PointCloudProvider.h:95
visionx::KinectV2PointCloudProvider::doCapture
bool doCapture() override
Definition: KinectV2PointCloudProvider.cpp:234
visionx::KinectV2PointCloudProvider::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinectV2PointCloudProvider.h:176
KinectHelpers.h
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
visionx::KinectV2PointCloudProvider::onExitImageProvider
void onExitImageProvider() override
Definition: KinectV2PointCloudProvider.h:147
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::KinectV2PointCloudProvider::getStereoCalibration
StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinectV2PointCloudProvider.cpp:282
visionx::KinectV2PointCloudProvider::KinectV2PointCloudProvider
KinectV2PointCloudProvider()
Definition: KinectV2PointCloudProvider.h:104
visionx::KinectV2PointCloudProvider::onInitComponent
void onInitComponent() override
Definition: KinectV2PointCloudProvider.cpp:45
visionx::CPU
@ CPU
Definition: KinectV2PointCloudProvider.h:56
Color
uint32_t Color
RGBA color.
Definition: color.h:8
visionx::CapturingPointCloudProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingPointCloudProvider.h:214
visionx::KinectV2PointCloudProvider::onInitCapturingPointCloudProvider
void onInitCapturingPointCloudProvider() override
Definition: KinectV2PointCloudProvider.cpp:82
ImageProcessor.h
visionx::CapturingPointCloudProviderPropertyDefinitions
Definition: CapturingPointCloudProvider.h:38
visionx::KinectV2PointCloudProvider::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: KinectV2PointCloudProvider.h:108
visionx::KinectV2PointCloudProvider::onExitCapturingPointCloudProvider
void onExitCapturingPointCloudProvider() override
Definition: KinectV2PointCloudProvider.cpp:213
visionx::KinectV2PointCloudProvider::getImagesAreUndistorted
bool getImagesAreUndistorted(const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: KinectV2PointCloudProvider.h:170
armarx::navigation::platform_controller::platform_global_trajectory::Registration
const NJointControllerRegistration< Controller > Registration(common::ControllerTypeNames.to_name(common::ControllerType::PlatformGlobalTrajectory))
visionx::KinectV2PointCloudProviderPropertyDefinitions::KinectV2PointCloudProviderPropertyDefinitions
KinectV2PointCloudProviderPropertyDefinitions(std::string prefix)
Definition: KinectV2PointCloudProvider.h:67
visionx::OPENCLKDE
@ OPENCLKDE
Definition: KinectV2PointCloudProvider.h:56
visionx::KinectV2PointCloudProvider::onInitImageProvider
void onInitImageProvider() override
Definition: KinectV2PointCloudProvider.cpp:225
visionx::KinectV2PointCloudProvider::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: KinectV2PointCloudProvider.cpp:63
visionx::KinectV2PointCloudProvider::onStopCapture
void onStopCapture() override
Definition: KinectV2PointCloudProvider.cpp:200
Component.h
visionx::CapturingPointCloudProvider
The CapturingPointCloudProvider provides a callback function to trigger the capturing of point clouds...
Definition: CapturingPointCloudProvider.h:56
visionx::KinectV2PointCloudProvider::onExitComponent
void onExitComponent() override
Definition: KinectV2PointCloudProvider.cpp:72
visionx::KinectV2PointCloudProvider::onConnectComponent
void onConnectComponent() override
Definition: KinectV2PointCloudProvider.cpp:54
visionx::KinectProcessorType
KinectProcessorType
Definition: KinectV2PointCloudProvider.h:54
visionx::ImageProvider
ImageProvider abstract class defines a component which provide images via ice or shared memory.
Definition: ImageProvider.h:66
visionx::KinectV2PointCloudProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: KinectV2PointCloudProvider.cpp:265
visionx::OPENCL
@ OPENCL
Definition: KinectV2PointCloudProvider.h:56
IceUtil::Handle< class PropertyDefinitionContainer >
KinectToIVTHelper
Definition: KinectHelpers.h:133
KinectToPCLHelper
Definition: KinectHelpers.h:37
visionx::OPENGL
@ OPENGL
Definition: KinectV2PointCloudProvider.h:56
ArmarXDataPath.h
visionx::CUDAKDE
@ CUDAKDE
Definition: KinectV2PointCloudProvider.h:56
visionx::KinectV2PointCloudProviderPropertyDefinitions
Definition: KinectV2PointCloudProvider.h:63
visionx::KinectV2PointCloudProvider::onStartCapture
void onStartCapture(float frameRate) override
Definition: KinectV2PointCloudProvider.cpp:170
visionx::PointT
pcl::PointXYZRGBA PointT
Definition: MaskRCNNPointCloudObjectLocalizer.h:79