43 #include <pcl/pcl_config.h>
48 #include <pcl/point_cloud.h>
49 #include <pcl/io/grabber.h>
50 #include <pcl/io/openni2/openni2_device.h>
52 #include <pcl/common/synchronizer.h>
54 #include <pcl/io/image.h>
55 #include <pcl/io/image_rgb24.h>
56 #include <pcl/io/image_yuv422.h>
57 #include <pcl/io/image_depth.h>
58 #include <pcl/io/image_ir.h>
76 using Ptr = shared_ptr<OpenNI2Grabber>;
77 using ConstPtr = shared_ptr<const OpenNI2Grabber>;
85 struct CameraParameters
88 double focal_length_x;
90 double focal_length_y;
92 double principal_point_x;
94 double principal_point_y;
96 CameraParameters (
double initValue)
97 : focal_length_x (initValue), focal_length_y (initValue),
98 principal_point_x (initValue), principal_point_y (initValue)
101 CameraParameters (
double fx,
double fy,
double cx,
double cy)
102 : focal_length_x (fx), focal_length_y (fy), principal_point_x (cx), principal_point_y (cy)
108 OpenNI_Default_Mode = 0,
109 OpenNI_SXGA_15Hz = 1,
112 OpenNI_QVGA_25Hz = 4,
113 OpenNI_QVGA_30Hz = 5,
114 OpenNI_QVGA_60Hz = 6,
115 OpenNI_QQVGA_25Hz = 7,
116 OpenNI_QQVGA_30Hz = 8,
117 OpenNI_QQVGA_60Hz = 9
121 using sig_cb_openni_image = void (
const Image::Ptr &);
123 using sig_cb_openni_ir_image = void (
const IRImage::Ptr &);
143 OpenNI2Grabber (
const std::string& device_id =
"",
144 const Mode& depth_mode = OpenNI_Default_Mode,
145 const Mode& image_mode = OpenNI_Default_Mode);
148 ~OpenNI2Grabber () noexcept override;
160 isRunning () const override;
163 getName () const override;
167 getFramesPerSecond () const override;
170 inline
pcl::io::openni2::OpenNI2Device::Ptr
174 std::vector<std::pair<
int,
pcl::io::openni2::OpenNI2VideoMode> >
175 getAvailableDepthModes () const;
178 std::vector<std::pair<
int,
pcl::io::openni2::OpenNI2VideoMode> >
179 getAvailableImageModes () const;
190 setRGBCameraIntrinsics (const
double rgb_focal_length_x,
191 const
double rgb_focal_length_y,
192 const
double rgb_principal_point_x,
193 const
double rgb_principal_point_y)
195 rgb_parameters_ = CameraParameters (
196 rgb_focal_length_x, rgb_focal_length_y,
197 rgb_principal_point_x, rgb_principal_point_y);
207 getRGBCameraIntrinsics (
double &rgb_focal_length_x,
208 double &rgb_focal_length_y,
209 double &rgb_principal_point_x,
210 double &rgb_principal_point_y)
const
212 rgb_focal_length_x = rgb_parameters_.focal_length_x;
213 rgb_focal_length_y = rgb_parameters_.focal_length_y;
214 rgb_principal_point_x = rgb_parameters_.principal_point_x;
215 rgb_principal_point_y = rgb_parameters_.principal_point_y;
226 setRGBFocalLength (
const double rgb_focal_length)
228 rgb_parameters_.focal_length_x = rgb_focal_length;
229 rgb_parameters_.focal_length_y = rgb_focal_length;
240 setRGBFocalLength (
const double rgb_focal_length_x,
const double rgb_focal_length_y)
242 rgb_parameters_.focal_length_x = rgb_focal_length_x;
243 rgb_parameters_.focal_length_y = rgb_focal_length_y;
251 getRGBFocalLength (
double &rgb_focal_length_x,
double &rgb_focal_length_y)
const
253 rgb_focal_length_x = rgb_parameters_.focal_length_x;
254 rgb_focal_length_y = rgb_parameters_.focal_length_y;
266 setDepthCameraIntrinsics (
const double depth_focal_length_x,
267 const double depth_focal_length_y,
268 const double depth_principal_point_x,
269 const double depth_principal_point_y)
271 depth_parameters_ = CameraParameters (
272 depth_focal_length_x, depth_focal_length_y,
273 depth_principal_point_x, depth_principal_point_y);
283 getDepthCameraIntrinsics (
double &depth_focal_length_x,
284 double &depth_focal_length_y,
285 double &depth_principal_point_x,
286 double &depth_principal_point_y)
const
288 depth_focal_length_x = depth_parameters_.focal_length_x;
289 depth_focal_length_y = depth_parameters_.focal_length_y;
290 depth_principal_point_x = depth_parameters_.principal_point_x;
291 depth_principal_point_y = depth_parameters_.principal_point_y;
300 setDepthFocalLength (
const double depth_focal_length)
302 depth_parameters_.focal_length_x = depth_focal_length;
303 depth_parameters_.focal_length_y = depth_focal_length;
314 setDepthFocalLength (
const double depth_focal_length_x,
const double depth_focal_length_y)
316 depth_parameters_.focal_length_x = depth_focal_length_x;
317 depth_parameters_.focal_length_y = depth_focal_length_y;
325 getDepthFocalLength (
double &depth_focal_length_x,
double &depth_focal_length_y)
const
327 depth_focal_length_x = depth_parameters_.focal_length_x;
328 depth_focal_length_y = depth_parameters_.focal_length_y;
335 setupDevice (
const std::string& device_id,
const Mode& depth_mode,
const Mode& image_mode);
343 startSynchronization ();
347 stopSynchronization ();
379 signalsChanged ()
override;
385 checkImageAndDepthSynchronizationRequired ();
389 checkImageStreamRequired ();
393 checkDepthStreamRequired ();
397 checkIRStreamRequired ();
424 std::vector<std::uint8_t> color_resize_buffer_{};
425 std::vector<std::uint16_t> depth_resize_buffer_{};
426 std::vector<std::uint16_t> ir_resize_buffer_{};
430 processColorFrame (openni::VideoStream& stream);
433 processDepthFrame (openni::VideoStream& stream);
436 processIRFrame (openni::VideoStream& stream);
439 Synchronizer<pcl::io::openni2::Image::Ptr, pcl::io::openni2::DepthImage::Ptr > rgb_sync_;
440 Synchronizer<pcl::io::openni2::IRImage::Ptr, pcl::io::openni2::DepthImage::Ptr > ir_sync_;
445 std::string rgb_frame_id_;
446 std::string depth_frame_id_;
447 unsigned image_width_{0};
448 unsigned image_height_{0};
449 unsigned depth_width_{0};
450 unsigned depth_height_{0};
452 bool image_required_{
false};
453 bool depth_required_{
false};
454 bool ir_required_{
false};
455 bool sync_required_{
false};
457 boost::signals2::signal<sig_cb_openni_image>* image_signal_{};
458 boost::signals2::signal<sig_cb_openni_depth_image>* depth_image_signal_{};
459 boost::signals2::signal<sig_cb_openni_ir_image>* ir_image_signal_{};
460 boost::signals2::signal<sig_cb_openni_image_depth_image>* image_depth_image_signal_{};
461 boost::signals2::signal<sig_cb_openni_ir_depth_image>* ir_depth_image_signal_{};
462 boost::signals2::signal<sig_cb_openni_point_cloud>* point_cloud_signal_{};
463 boost::signals2::signal<sig_cb_openni_point_cloud_i>* point_cloud_i_signal_{};
464 boost::signals2::signal<sig_cb_openni_point_cloud_rgb>* point_cloud_rgb_signal_{};
465 boost::signals2::signal<sig_cb_openni_point_cloud_rgba>* point_cloud_rgba_signal_{};
469 bool operator () (
const openni::VideoMode& mode1,
const openni::VideoMode & mode2)
const
471 if (mode1.getResolutionX () < mode2.getResolutionX ())
473 if (mode1.getResolutionX () > mode2.getResolutionX ())
475 if (mode1.getResolutionY () < mode2.getResolutionY ())
477 if (mode1.getResolutionY () > mode2.getResolutionY ())
479 return (mode1.getFps () < mode2.getFps ());
484 std::map<int, pcl::io::openni2::OpenNI2VideoMode> config2oni_map_;
489 bool running_{
false};
491 CameraParameters rgb_parameters_{std::numeric_limits<double>::quiet_NaN ()};
492 CameraParameters depth_parameters_{std::numeric_limits<double>::quiet_NaN ()};
499 OpenNI2Grabber::getDevice ()
const
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
This class provides methods to fill a depth or disparity image.
shared_ptr< DepthImage > Ptr
Class containing just a reference to IR meta data.
shared_ptr< IRImage > Ptr
Image interface class providing an interface to fill a RGB or Grayscale image buffer.
shared_ptr< OpenNI2Device > Ptr
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Defines functions, macros and traits for allocating and using memory.
DeviceArray2D< uchar4 > Image
pcl::io::DepthImage DepthImage
Defines all the PCL and non-PCL macros used.