40 #include <pcl/pcl_config.h>
41 #include <pcl/memory.h>
44 #include "openni_exception.h"
47 #include <pcl/io/boost.h>
48 #include <pcl/io/openni_camera/openni_image.h>
49 #include <pcl/io/openni_camera/openni_depth_image.h>
50 #include <pcl/io/openni_camera/openni_ir_image.h>
51 #include <pcl/pcl_macros.h>
53 #include <condition_variable>
78 OpenNI_shift_values = 0,
79 OpenNI_12_bit_depth = 1,
82 using Ptr = pcl::shared_ptr<OpenNIDevice>;
83 using ConstPtr = pcl::shared_ptr<const OpenNIDevice>;
103 findCompatibleImageMode (const XnMapOutputMode& output_mode, XnMapOutputMode& mode ) const throw ();
113 findCompatibleDepthMode (const XnMapOutputMode& output_mode, XnMapOutputMode& mode ) const throw ();
120 isImageModeSupported (const XnMapOutputMode& output_mode) const throw ();
127 isDepthModeSupported (const XnMapOutputMode& output_mode) const throw ();
132 const XnMapOutputMode&
133 getDefaultImageMode () const throw ();
138 const XnMapOutputMode&
139 getDefaultDepthMode () const throw ();
144 const XnMapOutputMode&
145 getDefaultIRMode () const throw ();
151 setImageOutputMode (const XnMapOutputMode& output_mode);
157 setDepthOutputMode (const XnMapOutputMode& output_mode);
163 setIROutputMode (const XnMapOutputMode& output_mode);
167 getImageOutputMode () const;
171 getDepthOutputMode () const;
175 getIROutputMode () const;
181 setDepthRegistration (
bool on_off);
185 isDepthRegistered () const throw ();
189 isDepthRegistrationSupported () const throw ();
195 setSynchronization (
bool on_off);
199 isSynchronized () const throw ();
203 isSynchronizationSupported () const throw ();
207 isDepthCropped () const;
216 setDepthCropping (
unsigned x,
unsigned y,
unsigned width,
unsigned height);
220 isDepthCroppingSupported () const throw ();
226 getImageFocalLength (
int output_x_resolution = 0) const throw ();
232 getDepthFocalLength (
int output_x_resolution = 0) const throw ();
236 getBaseline () const throw ();
264 hasImageStream () const throw ();
268 hasDepthStream () const throw ();
272 hasIRStream () const throw ();
276 isImageStreamRunning () const throw ();
280 isDepthStreamRunning () const throw ();
284 isIRStreamRunning () const throw ();
304 registerImageCallback (
void (T::*callback)(
Image::
Ptr,
void* cookie), T& instance,
void* cookie =
nullptr) noexcept;
311 unregisterImageCallback (const
CallbackHandle& callbackHandle) noexcept;
332 registerDepthCallback (
void (T::*callback)(
DepthImage::Ptr,
void* cookie), T& instance,
void* cookie =
nullptr) noexcept;
339 unregisterDepthCallback (const
CallbackHandle& callbackHandle) noexcept;
359 registerIRCallback (
void (T::*callback)(
IRImage::Ptr,
void* cookie), T& instance,
void* cookie =
nullptr) noexcept;
366 unregisterIRCallback (const
CallbackHandle& callbackHandle) noexcept;
372 getSerialNumber () const throw ();
376 getConnectionString () const throw ();
380 getVendorName () const throw ();
384 getProductName () const throw ();
388 getVendorID () const throw ();
392 getProductID () const throw ();
396 getBus () const throw ();
400 getAddress () const throw ();
406 setRGBFocalLength (
float focal_length)
408 rgb_focal_length_SXGA_ = focal_length;
417 depth_focal_length_SXGA_ = focal_length;
424 setDepthOutputFormat (
const DepthMode& depth_mode = OpenNI_12_bit_depth);
428 getDepthOutputFormat ()
const;
435 assert (shift_conversion_parameters_.init_);
437 std::uint16_t ret = 0;
440 if (shift_value<shift_to_depth_table_.size())
441 ret = shift_to_depth_table_[shift_value];
455 OpenNIDevice (xn::Context& context,
const xn::NodeInfo& device_node,
const xn::NodeInfo& image_node,
const xn::NodeInfo& depth_node,
const xn::NodeInfo& ir_node);
456 OpenNIDevice (xn::Context& context,
const xn::NodeInfo& device_node,
const xn::NodeInfo& depth_node,
const xn::NodeInfo& ir_node);
458 static void __stdcall NewDepthDataAvailable (xn::ProductionNode& node,
void* cookie) noexcept;
459 static void __stdcall NewImageDataAvailable (xn::ProductionNode& node,
void* cookie) noexcept;
460 static void __stdcall NewIRDataAvailable (xn::ProductionNode& node,
void* cookie) noexcept;
465 ImageDataThreadFunction ();
468 DepthDataThreadFunction ();
471 IRDataThreadFunction ();
474 isImageResizeSupported (
unsigned input_width,
unsigned input_height,
unsigned output_width,
unsigned output_height)
const throw () = 0;
477 setRegistration (
bool on_off);
480 getCurrentImage (pcl::shared_ptr<xn::ImageMetaData> image_data)
const throw () = 0;
485 void InitShiftToDepthConversion();
486 void ReadDeviceParametersFromSensorNode();
505 } shift_conversion_parameters_;
567 if (output_x_resolution == 0)
568 output_x_resolution = getImageOutputMode ().nXRes;
570 float scale =
static_cast<float> (output_x_resolution) / static_cast<float> (XN_SXGA_X_RES);
571 return (rgb_focal_length_SXGA_ * scale);
578 if (output_x_resolution == 0)
579 output_x_resolution = getDepthOutputMode ().nXRes;
581 float scale =
static_cast<float> (output_x_resolution) / static_cast<float> (XN_SXGA_X_RES);
582 if (isDepthRegistered ())
583 return (rgb_focal_length_SXGA_ * scale);
584 return (depth_focal_length_SXGA_ * scale);
598 image_callback_[image_callback_handle_counter_] = [=, &instance] (
Image::Ptr img) { (instance.*callback) (img, custom_data); };
599 return (image_callback_handle_counter_++);
606 depth_callback_[depth_callback_handle_counter_] = [=, &instance] (
DepthImage::Ptr img) { (instance.*callback) (img, custom_data); };
607 return (depth_callback_handle_counter_++);
614 ir_callback_[ir_callback_handle_counter_] = [=, &instance] (
IRImage::Ptr img) { (instance.*callback) (img, custom_data); };
615 return (ir_callback_handle_counter_++);
619 #endif // HAVE_OPENNI
std::vector< XnMapOutputMode > available_depth_modes_
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...
float getImageFocalLength(int output_x_resolution=0) const
returns the focal length for the color camera in pixels.
xn::ImageGenerator image_generator_
Image generator object.
std::condition_variable depth_condition_
float getDepthFocalLength(int output_x_resolution=0) const
returns the focal length for the IR camera in pixels.
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
float getBaseline() const
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
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
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)