40 #include <pcl/pcl_config.h>
41 #include <pcl/memory.h>
44 #include "openni_exception.h"
47 #include <pcl/io/openni_camera/openni_image.h>
48 #include <pcl/io/openni_camera/openni_depth_image.h>
49 #include <pcl/io/openni_camera/openni_ir_image.h>
50 #include <pcl/pcl_macros.h>
52 #include <condition_variable>
76 OpenNI_shift_values = 0,
77 OpenNI_12_bit_depth = 1,
80 using Ptr = pcl::shared_ptr<OpenNIDevice>;
81 using ConstPtr = pcl::shared_ptr<const OpenNIDevice>;
101 findCompatibleImageMode (const XnMapOutputMode& output_mode, XnMapOutputMode& mode ) const noexcept;
111 findCompatibleDepthMode (const XnMapOutputMode& output_mode, XnMapOutputMode& mode ) const noexcept;
118 isImageModeSupported (const XnMapOutputMode& output_mode) const noexcept;
125 isDepthModeSupported (const XnMapOutputMode& output_mode) const noexcept;
130 const XnMapOutputMode&
131 getDefaultImageMode () const noexcept;
136 const XnMapOutputMode&
137 getDefaultDepthMode () const noexcept;
142 const XnMapOutputMode&
143 getDefaultIRMode () const noexcept;
149 setImageOutputMode (const XnMapOutputMode& output_mode);
155 setDepthOutputMode (const XnMapOutputMode& output_mode);
161 setIROutputMode (const XnMapOutputMode& output_mode);
165 getImageOutputMode () const;
169 getDepthOutputMode () const;
173 getIROutputMode () const;
179 setDepthRegistration (
bool on_off);
183 isDepthRegistered () const noexcept;
187 isDepthRegistrationSupported () const noexcept;
193 setSynchronization (
bool on_off);
197 isSynchronized () const noexcept;
201 isSynchronizationSupported () const noexcept;
205 isDepthCropped () const;
214 setDepthCropping (
unsigned x,
unsigned y,
unsigned width,
unsigned height);
218 isDepthCroppingSupported () const noexcept;
224 getImageFocalLength (
int output_x_resolution = 0) const noexcept;
230 getDepthFocalLength (
int output_x_resolution = 0) const noexcept;
234 getBaseline () const noexcept;
262 hasImageStream () const noexcept;
266 hasDepthStream () const noexcept;
270 hasIRStream () const noexcept;
274 isImageStreamRunning () const noexcept;
278 isDepthStreamRunning () const noexcept;
282 isIRStreamRunning () const noexcept;
302 registerImageCallback (
void (T::*callback)(
Image::
Ptr,
void* cookie), T& instance,
void* cookie =
nullptr) noexcept;
309 unregisterImageCallback (const
CallbackHandle& callbackHandle) noexcept;
330 registerDepthCallback (
void (T::*callback)(
DepthImage::Ptr,
void* cookie), T& instance,
void* cookie =
nullptr) noexcept;
337 unregisterDepthCallback (const
CallbackHandle& callbackHandle) noexcept;
357 registerIRCallback (
void (T::*callback)(
IRImage::Ptr,
void* cookie), T& instance,
void* cookie =
nullptr) noexcept;
364 unregisterIRCallback (const
CallbackHandle& callbackHandle) noexcept;
370 getSerialNumber () const noexcept;
374 getConnectionString () const noexcept;
378 getVendorName () const noexcept;
382 getProductName () const noexcept;
386 getVendorID () const noexcept;
390 getProductID () const noexcept;
394 getBus () const noexcept;
398 getAddress () const noexcept;
404 setRGBFocalLength (
float focal_length)
406 rgb_focal_length_SXGA_ = focal_length;
415 depth_focal_length_SXGA_ = focal_length;
422 setDepthOutputFormat (
const DepthMode& depth_mode = OpenNI_12_bit_depth);
426 getDepthOutputFormat ()
const;
433 assert (shift_conversion_parameters_.init_);
435 std::uint16_t ret = 0;
438 if (shift_value<shift_to_depth_table_.size())
439 ret = shift_to_depth_table_[shift_value];
453 OpenNIDevice (xn::Context& context,
const xn::NodeInfo& device_node,
const xn::NodeInfo& image_node,
const xn::NodeInfo& depth_node,
const xn::NodeInfo& ir_node);
454 OpenNIDevice (xn::Context& context,
const xn::NodeInfo& device_node,
const xn::NodeInfo& depth_node,
const xn::NodeInfo& ir_node);
456 static void __stdcall NewDepthDataAvailable (xn::ProductionNode& node,
void* cookie) noexcept;
457 static void __stdcall NewImageDataAvailable (xn::ProductionNode& node,
void* cookie) noexcept;
458 static void __stdcall NewIRDataAvailable (xn::ProductionNode& node,
void* cookie) noexcept;
463 ImageDataThreadFunction ();
466 DepthDataThreadFunction ();
469 IRDataThreadFunction ();
472 isImageResizeSupported (
unsigned input_width,
unsigned input_height,
unsigned output_width,
unsigned output_height)
const noexcept = 0;
475 setRegistration (
bool on_off);
478 getCurrentImage (pcl::shared_ptr<xn::ImageMetaData> image_data)
const noexcept = 0;
483 void InitShiftToDepthConversion();
484 void ReadDeviceParametersFromSensorNode();
503 } shift_conversion_parameters_;
565 if (output_x_resolution == 0)
566 output_x_resolution = getImageOutputMode ().nXRes;
568 float scale =
static_cast<float> (output_x_resolution) / static_cast<float> (XN_SXGA_X_RES);
569 return (rgb_focal_length_SXGA_ * scale);
576 if (output_x_resolution == 0)
577 output_x_resolution = getDepthOutputMode ().nXRes;
579 float scale =
static_cast<float> (output_x_resolution) / static_cast<float> (XN_SXGA_X_RES);
580 if (isDepthRegistered ())
581 return (rgb_focal_length_SXGA_ * scale);
582 return (depth_focal_length_SXGA_ * scale);
596 image_callback_[image_callback_handle_counter_] = [=, &instance] (
Image::Ptr img) { (instance.*callback) (img, custom_data); };
597 return (image_callback_handle_counter_++);
604 depth_callback_[depth_callback_handle_counter_] = [=, &instance] (
DepthImage::Ptr img) { (instance.*callback) (img, custom_data); };
605 return (depth_callback_handle_counter_++);
612 ir_callback_[ir_callback_handle_counter_] = [=, &instance] (
IRImage::Ptr img) { (instance.*callback) (img, custom_data); };
613 return (ir_callback_handle_counter_++);
617 #endif // HAVE_OPENNI
std::vector< XnMapOutputMode > available_depth_modes_
float getDepthFocalLength(int output_x_resolution=0) const noexcept
returns the focal length for the IR camera in pixels.
CallbackHandle registerIRCallback(const IRImageCallbackFunction &callback, void *cookie=nullptr) noexcept
registers a callback function of std::function type for the IR stream with an optional user defined p...
std::map< CallbackHandle, ActualImageCallbackFunction > image_callback_
std::vector< std::uint16_t > shift_to_depth_table_
Class representing an astract device for OpenNI devices: Primesense PSDK, Microsoft Kinect...
CallbackHandle registerDepthCallback(const DepthImageCallbackFunction &callback, void *cookie=nullptr) noexcept
registers a callback function of std::function type for the depth stream with an optional user define...
xn::ImageGenerator image_generator_
Image generator object.
std::condition_variable depth_condition_
std::condition_variable ir_condition_
XnUInt64 no_sample_value_
the value for pixels without a valid disparity measurement
std::vector< XnMapOutputMode > available_image_modes_
void setDepthFocalLength(float focal_length)
Set the depth image focal length.
Image class containing just a reference to image meta data.
XnUInt32 device_max_shift_
std::function< void(Image::Ptr) > ActualImageCallbackFunction
OpenNIDevice::CallbackHandle ir_callback_handle_counter_
std::thread image_thread_
float baseline_
distance between the projector and the IR camera
xn::Context & context_
context to OpenNI driver
OpenNIDevice::CallbackHandle depth_callback_handle_counter_
pcl::shared_ptr< const OpenNIDevice > ConstPtr
std::function< void(IRImage::Ptr, void *cookie) > IRImageCallbackFunction
std::function< void(DepthImage::Ptr) > ActualDepthImageCallbackFunction
This class provides methods to fill a depth or disparity image.
std::function< void(DepthImage::Ptr, void *cookie) > DepthImageCallbackFunction
pcl::shared_ptr< IRImage > Ptr
xn::IRGenerator ir_generator_
IR generator object.
std::uint16_t shiftToDepth(std::uint16_t shift_value) const
Convert shift to depth value.
XnUInt16 zero_plane_distance_
XnCallbackHandle depth_callback_handle_
std::thread depth_thread_
std::function< void(IRImage::Ptr) > ActualIRImageCallbackFunction
float getImageFocalLength(int output_x_resolution=0) const noexcept
returns the focal length for the color camera in pixels.
XnUInt32 pixel_size_factor_
pcl::shared_ptr< OpenNIDevice > Ptr
xn::NodeInfo device_node_info_
node object for current device
OpenNIDevice::CallbackHandle image_callback_handle_counter_
float rgb_focal_length_SXGA_
focal length for regular camera producing color images in native SXGA mode
std::map< CallbackHandle, ActualDepthImageCallbackFunction > depth_callback_
std::map< CallbackHandle, ActualIRImageCallbackFunction > ir_callback_
pcl::shared_ptr< Image > Ptr
float getBaseline() const noexcept
pcl::shared_ptr< DepthImage > Ptr
XnCallbackHandle ir_callback_handle_
std::function< void(Image::Ptr, void *cookie) > ImageCallbackFunction
XnFloat zero_plane_pixel_size_
xn::DepthGenerator depth_generator_
Depth generator object.
float depth_focal_length_SXGA_
focal length for IR camera producing depth information in native SXGA mode
Class containing just a reference to IR meta data.
CallbackHandle registerImageCallback(const ImageCallbackFunction &callback, void *cookie=nullptr) noexcept
registers a callback function of std::function type for the image stream with an optional user define...
XnCallbackHandle image_callback_handle_
std::condition_variable image_condition_
XnFloat emitter_dcmos_distace_
XnUInt64 shadow_value_
the value for shadow (occluded pixels)