40 #include <pcl/pcl_config.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>
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;
330 registerDepthCallback (
void (T::*callback)(
DepthImage::
Ptr,
void* cookie), T& instance,
void* cookie =
nullptr) noexcept;
357 registerIRCallback (
void (T::*callback)(
IRImage::
Ptr,
void* cookie), T& instance,
void* cookie =
nullptr) 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;
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);
472 isImageResizeSupported (
unsigned input_width,
unsigned input_height,
unsigned output_width,
unsigned output_height)
const noexcept = 0;
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_++);
This class provides methods to fill a depth or disparity image.
pcl::shared_ptr< DepthImage > Ptr
Class containing just a reference to IR meta data.
pcl::shared_ptr< IRImage > Ptr
Image class containing just a reference to image meta data.
pcl::shared_ptr< Image > Ptr
Class representing an astract device for OpenNI devices: Primesense PSDK, Microsoft Kinect,...
float rgb_focal_length_SXGA_
focal length for regular camera producing color images in native SXGA mode
OpenNIDevice::CallbackHandle depth_callback_handle_counter_
XnUInt64 shadow_value_
the value for shadow (occluded pixels)
std::function< void(DepthImage::Ptr, void *cookie) > DepthImageCallbackFunction
std::map< CallbackHandle, ActualIRImageCallbackFunction > ir_callback_
void setDepthFocalLength(float focal_length)
Set the depth image focal length.
std::map< CallbackHandle, ActualImageCallbackFunction > image_callback_
std::function< void(Image::Ptr) > ActualImageCallbackFunction
xn::IRGenerator ir_generator_
IR generator object.
float baseline_
distance between the projector and the IR camera
std::function< void(IRImage::Ptr, void *cookie) > IRImageCallbackFunction
float depth_focal_length_SXGA_
focal length for IR camera producing depth information in native SXGA mode
XnCallbackHandle ir_callback_handle_
xn::ImageGenerator image_generator_
Image generator object.
std::function< void(DepthImage::Ptr) > ActualDepthImageCallbackFunction
virtual Image::Ptr getCurrentImage(pcl::shared_ptr< xn::ImageMetaData > image_data) const noexcept=0
std::vector< std::uint16_t > shift_to_depth_table_
float getDepthFocalLength(int output_x_resolution=0) const noexcept
returns the focal length for the IR camera in pixels.
static void __stdcall NewImageDataAvailable(xn::ProductionNode &node, void *cookie) noexcept
void DepthDataThreadFunction()
std::function< void(Image::Ptr, void *cookie) > ImageCallbackFunction
XnCallbackHandle image_callback_handle_
XnUInt64 getDepthOutputFormat() const
Get the depth output format as set by the user.
std::function< void(IRImage::Ptr) > ActualIRImageCallbackFunction
static void __stdcall NewIRDataAvailable(xn::ProductionNode &node, void *cookie) noexcept
void InitShiftToDepthConversion()
std::thread depth_thread_
std::uint16_t shiftToDepth(std::uint16_t shift_value) const
Convert shift to depth value.
OpenNIDevice(xn::Context &context, const xn::NodeInfo &device_node, const xn::NodeInfo &image_node, const xn::NodeInfo &depth_node, const xn::NodeInfo &ir_node)
pcl::shared_ptr< OpenNIDevice > Ptr
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...
std::condition_variable ir_condition_
xn::NodeInfo device_node_info_
node object for current device
void ImageDataThreadFunction()
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 getBaseline() const noexcept
OpenNIDevice(xn::Context &context)
static void __stdcall NewDepthDataAvailable(xn::ProductionNode &node, void *cookie) noexcept
OpenNIDevice::CallbackHandle image_callback_handle_counter_
xn::DepthGenerator depth_generator_
Depth generator object.
xn::Context & context_
context to OpenNI driver
void setDepthOutputFormat(const DepthMode &depth_mode=OpenNI_12_bit_depth)
Set the depth output format.
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...
void IRDataThreadFunction()
std::vector< XnMapOutputMode > available_image_modes_
virtual bool isImageResizeSupported(unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height) const noexcept=0
OpenNIDevice(xn::Context &context, const xn::NodeInfo &device_node, const xn::NodeInfo &depth_node, const xn::NodeInfo &ir_node)
std::vector< XnMapOutputMode > available_depth_modes_
OpenNIDevice::CallbackHandle ir_callback_handle_counter_
std::condition_variable image_condition_
std::map< CallbackHandle, ActualDepthImageCallbackFunction > depth_callback_
pcl::shared_ptr< const OpenNIDevice > ConstPtr
void ReadDeviceParametersFromSensorNode()
void setRegistration(bool on_off)
std::condition_variable depth_condition_
std::thread image_thread_
virtual ~OpenNIDevice() noexcept
virtual destructor.
XnUInt64 no_sample_value_
the value for pixels without a valid disparity measurement
float getImageFocalLength(int output_x_resolution=0) const noexcept
returns the focal length for the color camera in pixels.
XnCallbackHandle depth_callback_handle_
Defines functions, macros and traits for allocating and using memory.
Defines all the PCL and non-PCL macros used.
XnFloat zero_plane_pixel_size_
XnUInt32 pixel_size_factor_
XnUInt32 device_max_shift_
XnFloat emitter_dcmos_distace_
XnUInt16 zero_plane_distance_
ShiftConversion()=default