OpenNIPointCloudProvider.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::OpenNIPointCloudProvider
19 * @author David Schiebener (schiebener at kit dot edu)
20 * @date 2015
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 <condition_variable>
37#include <mutex>
38
39#include <Eigen/Geometry>
40
41#include <pcl/common/transforms.h>
42#include <pcl/io/openni2_grabber.h>
43#include <pcl/point_cloud.h>
44#include <pcl/point_types.h>
45
46#include <opencv2/opencv.hpp>
47
49
50#include <RobotAPI/interface/components/RobotHealthInterface.h>
52
53#include <Image/IplImageAdaptor.h>
54
55namespace visionx
56{
57
58 /**
59 * @class OpenNIPointCloudProviderPropertyDefinitions
60 * @brief
61 */
64 {
65 public:
68 {
69 defineOptionalProperty<Eigen::Vector2i>("dimensions", Eigen::Vector2i(640, 480), "")
70 .map("320x240", Eigen::Vector2i(320, 240))
71 .map("640x480", Eigen::Vector2i(640, 480))
72 .map("800x600", Eigen::Vector2i(800, 600))
73 .map("1280x1024", Eigen::Vector2i(1280, 1024))
74 .map("1600x1200", Eigen::Vector2i(1600, 1200));
75
76 defineOptionalProperty<std::string>("depthCameraCalibrationFile",
77 "VisionX/camera_calibration/asus_xtion_depth.yaml",
78 "");
80 "RGBCameraCalibrationFile", "VisionX/camera_calibration/asus_xtion_rgb.yaml", "");
81
82 defineOptionalProperty<bool>("EnableAutoExposure", true, "enable auto exposure.");
84 "EnableAutoWhiteBalance", true, "enable auto white balance.");
85
87 "ReferenceFrameName", "DepthCamera", "Optional reference frame name.");
89 "",
90 "Device id of the openni device, e.g. empty for "
91 "first device, or index in the format #n, e.g. 0");
93 "CaptureTimeOffset",
94 16.0f,
95 "In Milliseconds. Time offset between capturing the image on the hardware and "
96 "receiving the image in this process.",
99 "RobotHealthTopicName", "RobotHealthTopic", "Name of the RobotHealth topic");
100 defineOptionalProperty<std::string>("DebugObserverName",
101 "DebugObserver",
102 "Name of the topic the DebugObserver listens on");
103 }
104 };
105
106 /**
107 * @class OpenNIPointCloudProvider
108 * @ingroup VisionX-Components
109 * @brief A brief description
110 *
111 * Detailed Description
112 */
114 virtual public RGBDPointCloudProviderInterface,
115 virtual public CapturingPointCloudProvider,
116 virtual public ImageProvider
117 {
118 public:
120
121 /**
122 * @see armarx::ManagedIceObject::getDefaultName()
123 */
124 static std::string GetDefaultName();
125 std::string getDefaultName() const override;
126
127 std::vector<imrec::ChannelPreferences>
128 getImageRecordingChannelPreferences(const Ice::Current&) override;
129
130 protected:
131 /**
132 * @see visionx::PointCloudProviderBase::onInitPointCloudProvider()
133 */
134 void onInitCapturingPointCloudProvider() override;
135
136
137 void onConnectPointCloudProvider() override;
138
139 /**
140 * @see visionx::PointCloudProviderBase::onExitPointCloudProvider()
141 */
142 void onExitCapturingPointCloudProvider() override;
143
144 /**
145 * @see visionx::PointCloudProviderBase::onStartCapture()
146 */
147 void onStartCapture(float frameRate) override;
148
149 /**
150 * @see visionx::PointCloudProviderBase::onStopCapture()
151 */
152 void onStopCapture() override;
153
154 /**
155 * @see visionx::PointCloudProviderBase::doCapture()
156 */
157 bool doCapture() override;
158
159 /**
160 * @see visionx::CapturingImageProvider::onInitImageProvider()
161 */
162 void onInitImageProvider() override;
163
164 /**
165 * @see visionx::CapturingImageProvider::onExitImageProvider()
166 */
167 void
169 {
170 }
171
172 bool
173 hasSharedMemorySupport(const Ice::Current& c = Ice::emptyCurrent) override
174 {
175 return true;
176 }
177
178 /**
179 * @see PropertyUser::createPropertyDefinitions()
180 */
182
183 // mixed inherited stuff
184 void onInitComponent() override;
185 void onConnectComponent() override;
186 void onDisconnectComponent() override;
187 void onExitComponent() override;
188
189
190 StereoCalibration getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override;
191
192 bool
193 getImagesAreUndistorted(const ::Ice::Current& c = Ice::emptyCurrent) override
194 {
195 return false;
196 }
197
198 std::string
199 getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override
200 {
201 return getProperty<std::string>("ReferenceFrameName");
202 }
203
204 private:
205 void callbackFunctionForOpenNIGrabberPointCloudWithRGB(
206 const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr& newCloud);
207 void callbackFunctionForOpenNIGrabberPointCloud(
208 const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& newCloud);
209 void callbackFunctionForOpenNIGrabberImage(const pcl::io::Image::Ptr& newImage);
210 void grabImages(const pcl::io::Image::Ptr& RGBImage,
211 const pcl::io::DepthImage::Ptr& depthImage,
212 float reciprocalFocalLength);
213 void grabDepthImage(const pcl::io::IRImage::Ptr& RGBImage,
214 const pcl::io::DepthImage::Ptr& depthImage,
215 float x);
216
217
218 bool loadCalibrationFile(std::string fileName, visionx::CameraParameters& calibration);
219
220 ImageProviderInterfacePrx imageProviderPrx;
221 std::string providerName;
222 CByteImage** rgbImages;
223 int width, height;
224 mutable std::mutex syncMutex;
225
226 pcl::io::OpenNI2Grabber::Ptr grabberInterface;
227 std::condition_variable condition;
228 bool newPointCloudCapturingRequested, newImageCapturingRequested;
229 long timeOfLastImageCapture, timeOfLastPointCloudCapture;
230 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pointcloudBuffer;
231 StereoCalibration calibration;
232 long captureTimeOffset;
233
234 armarx::RobotHealthInterfacePrx robotHealthTopic;
236 IceUtil::Time lastReportTimestamp;
237
238 armarx::plugins::HeartbeatComponentPlugin* heartbeatPlugin = nullptr;
239 };
240} // 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 onStartCapture(float frameRate) override
void onConnectComponent() override
Pure virtual hook for the subclass.
StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
std::vector< imrec::ChannelPreferences > getImageRecordingChannelPreferences(const Ice::Current &) 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
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.