28#include <pcl/io/pcd_io.h>
36#include <Calibration/Calibration.h>
37#include <Image/ImageProcessor.h>
108 switch (pipeline_type_)
111 pipeline_ =
new libfreenect2::CpuPacketPipeline();
114 pipeline_ =
new libfreenect2::OpenGLPacketPipeline();
117 pipeline_ =
new libfreenect2::OpenCLPacketPipeline(deviceId_);
120 pipeline_ =
new libfreenect2::OpenCLKdePacketPipeline(deviceId_);
123 pipeline_ =
new libfreenect2::CudaPacketPipeline(deviceId_);
126 pipeline_ =
new libfreenect2::CudaKdePacketPipeline(deviceId_);
129 pipeline_ =
new libfreenect2::CpuPacketPipeline();
134 if (!enable_rgb_ && !enable_depth_)
137 ARMARX_ERROR <<
"Either depth or rgb needs to be enabled";
139 if (freenect2_.enumerateDevices() == 0)
147 serial_ = freenect2_.getDefaultDeviceSerialNumber();
152 dev_ = freenect2_.openDevice(serial_, pipeline_);
157 dev_ = freenect2_.openDevice(serial_);
166 rgbImages_ =
new CByteImage*[2];
168 rgbImages_[0] =
new CByteImage(d_width_, d_height_, CByteImage::eRGB24);
169 rgbImages_[1] =
new CByteImage(d_width_, d_height_, CByteImage::eRGB24);
170 ::ImageProcessor::Zero(rgbImages_[0]);
171 ::ImageProcessor::Zero(rgbImages_[1]);
177 if (enable_rgb_ && enable_depth_)
188 if (!dev_->startStreams(enable_rgb_, enable_depth_))
193 libfreenect2::Freenect2Device::IrCameraParams depth_p =
194 dev_->getIrCameraParams();
195 libfreenect2::Freenect2Device::ColorCameraParams rgb_p = dev_->getColorCameraParams();
196 registration_ =
new libfreenect2::Registration(depth_p, rgb_p);
197 dev_->setColorFrameListener(&listener_);
198 dev_->setIrAndDepthFrameListener(&listener_);
201 initializeCameraCalibration();
208 ARMARX_INFO <<
"Stopping KinectV2 Grabber Interface";
214 ARMARX_INFO <<
"Stopped KinectV2 Grabber Interface";
223 delete rgbImages_[0];
224 delete rgbImages_[1];
233 Eigen::Vector2i dimensions = Eigen::Vector2i(512, 424);
234 setImageFormat(visionx::ImageDimension(dimensions(0), dimensions(1)), visionx::eRgb);
241 if (!listener_.waitForNewFrame(frames_, 1 * 1000))
247 pcl::PointCloud<PointT>::Ptr outputCloud =
248 pcl::PointCloud<PointT>::Ptr(
new pcl::PointCloud<PointT>());
251 libfreenect2::Frame* rgb = frames_[libfreenect2::Frame::Color];
253 libfreenect2::Frame* depth = frames_[libfreenect2::Frame::Depth];
254 if (enable_rgb_ && enable_depth_)
256 registration_->apply(rgb, depth, &undistorted_, ®istered_,
true);
258 ivtHelper->calculateImages(undistorted_, registered_, rgbImages_);
259 pclHelper->calculatePointCloud(undistorted_, registered_, outputCloud);
261 outputCloud->header.stamp = ts.toMicroSeconds();
262 outputCloud->header.seq = depth->sequence;
266 listener_.release(frames_);
277 libfreenect2::Freenect2Device::IrCameraParams
278 KinectV2PointCloudProvider::getCameraIrParameters()
280 libfreenect2::Freenect2Device::IrCameraParams ir = dev_->getIrCameraParams();
284 libfreenect2::Freenect2Device::ColorCameraParams
285 KinectV2PointCloudProvider::getCameraRGBParameters()
287 libfreenect2::Freenect2Device::ColorCameraParams rgb = dev_->getColorCameraParams();
298 KinectV2PointCloudProvider::initializeCameraCalibration()
300 visionx::CameraParameters RGBCameraIntrinsics;
301 RGBCameraIntrinsics.focalLength.resize(2, 0.0f);
302 RGBCameraIntrinsics.principalPoint.resize(2, 0.0f);
303 RGBCameraIntrinsics.distortion.resize(4, 0.0f);
306 RGBCameraIntrinsics.rotation =
308 RGBCameraIntrinsics.translation =
310 auto rgb_params = getCameraRGBParameters();
314 RGBCameraIntrinsics.principalPoint[0] = rgb_params.cx;
315 RGBCameraIntrinsics.principalPoint[1] = rgb_params.cy;
316 RGBCameraIntrinsics.focalLength[0] = rgb_params.fx;
317 RGBCameraIntrinsics.focalLength[1] = rgb_params.fy;
318 RGBCameraIntrinsics.width = rgb_width_;
319 RGBCameraIntrinsics.height = rgb_height_;
322 visionx::CameraParameters depthCameraIntrinsics;
323 depthCameraIntrinsics.focalLength.resize(2, 0.0f);
324 depthCameraIntrinsics.principalPoint.resize(2, 0.0f);
325 depthCameraIntrinsics.distortion.resize(4, 0.0f);
326 depthCameraIntrinsics.rotation =
328 depthCameraIntrinsics.translation =
331 auto d_params = getCameraIrParameters();
332 depthCameraIntrinsics.principalPoint[0] = d_params.cx;
333 depthCameraIntrinsics.principalPoint[1] = d_params.cy;
334 depthCameraIntrinsics.focalLength[0] = d_params.fx;
335 depthCameraIntrinsics.focalLength[1] = d_params.fy;
336 depthCameraIntrinsics.width = d_width_;
337 depthCameraIntrinsics.height = d_height_;
344 calibration.calibrationLeft.cameraParam = RGBCameraIntrinsics;
345 calibration.calibrationRight.cameraParam = depthCameraIntrinsics;
346 calibration.rectificationHomographyLeft =
348 calibration.rectificationHomographyRight =
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
virtual void onExitComponent()
Hook for subclass.
virtual void onDisconnectComponent()
Hook for subclass.
virtual void onConnectComponent()=0
Pure virtual hook for the subclass.
virtual void onInitComponent()=0
Pure virtual hook for the subclass.
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
float frameRate
Required frame rate.
std::atomic_bool captureEnabled
Indicates that capturing is enabled and running.
void onInitComponent() override
void onDisconnectComponent() override
Hook for subclass.
void setImageFormat(ImageDimension imageDimension, ImageType imageType, BayerPatternType bayerPatternType=visionx::eBayerPatternRg)
Sets the image basic format data.
void provideImages(void **inputBuffers, const IceUtil::Time &imageTimestamp=IceUtil::Time())
send images raw.
void onConnectComponent() override
void setNumberImages(int numberImages)
Sets the number of images on each capture.
void onExitComponent() override
void onInitComponent() override
Pure virtual hook for the subclass.
bool doCapture() override
void onExitCapturingPointCloudProvider() override
void onDisconnectComponent() override
Hook for subclass.
void onStartCapture(float frameRate) override
void onInitCapturingPointCloudProvider() override
void onConnectComponent() override
Pure virtual hook for the subclass.
StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
void onStopCapture() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onInitImageProvider() override
void onExitComponent() override
Hook for subclass.
void providePointCloud(PointCloudPtrT pointCloudPtr)
offer the new point cloud.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_VERBOSE
The logging level for verbose information.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.