42 #include <pcl/memory.h>
43 #include <pcl/pcl_config.h>
44 #include <pcl/pcl_macros.h>
48 #include <pcl/point_cloud.h>
49 #include <pcl/io/eigen.h>
50 #include <pcl/io/boost.h>
51 #include <pcl/io/grabber.h>
52 #include <pcl/io/openni2/openni2_device.h>
55 #include <pcl/common/synchronizer.h>
57 #include <pcl/io/image.h>
58 #include <pcl/io/image_rgb24.h>
59 #include <pcl/io/image_yuv422.h>
60 #include <pcl/io/image_depth.h>
61 #include <pcl/io/image_ir.h>
76 class PCL_EXPORTS OpenNI2Grabber :
public Grabber
79 using Ptr = shared_ptr<OpenNI2Grabber>;
80 using ConstPtr = shared_ptr<const OpenNI2Grabber>;
88 struct CameraParameters
91 double focal_length_x;
93 double focal_length_y;
95 double principal_point_x;
97 double principal_point_y;
99 CameraParameters (
double initValue)
100 : focal_length_x (initValue), focal_length_y (initValue),
101 principal_point_x (initValue), principal_point_y (initValue)
104 CameraParameters (
double fx,
double fy,
double cx,
double cy)
105 : focal_length_x (fx), focal_length_y (fy), principal_point_x (cx), principal_point_y (cy)
111 OpenNI_Default_Mode = 0,
112 OpenNI_SXGA_15Hz = 1,
115 OpenNI_QVGA_25Hz = 4,
116 OpenNI_QVGA_30Hz = 5,
117 OpenNI_QVGA_60Hz = 6,
118 OpenNI_QQVGA_25Hz = 7,
119 OpenNI_QQVGA_30Hz = 8,
120 OpenNI_QQVGA_60Hz = 9
124 using sig_cb_openni_image = void (
const Image::Ptr &);
126 using sig_cb_openni_ir_image = void (
const IRImage::Ptr &);
146 OpenNI2Grabber (
const std::string& device_id =
"",
147 const Mode& depth_mode = OpenNI_Default_Mode,
148 const Mode& image_mode = OpenNI_Default_Mode);
151 ~OpenNI2Grabber () noexcept;
163 isRunning () const override;
166 getName () const override;
170 getFramesPerSecond () const override;
173 inline
pcl::io::openni2::OpenNI2Device::Ptr
177 std::vector<
std::pair<
int,
pcl::io::openni2::OpenNI2VideoMode> >
178 getAvailableDepthModes () const;
181 std::vector<
std::pair<
int,
pcl::io::openni2::OpenNI2VideoMode> >
182 getAvailableImageModes () const;
193 setRGBCameraIntrinsics (const
double rgb_focal_length_x,
194 const
double rgb_focal_length_y,
195 const
double rgb_principal_point_x,
196 const
double rgb_principal_point_y)
198 rgb_parameters_ = CameraParameters (
199 rgb_focal_length_x, rgb_focal_length_y,
200 rgb_principal_point_x, rgb_principal_point_y);
210 getRGBCameraIntrinsics (
double &rgb_focal_length_x,
211 double &rgb_focal_length_y,
212 double &rgb_principal_point_x,
213 double &rgb_principal_point_y)
const
215 rgb_focal_length_x = rgb_parameters_.focal_length_x;
216 rgb_focal_length_y = rgb_parameters_.focal_length_y;
217 rgb_principal_point_x = rgb_parameters_.principal_point_x;
218 rgb_principal_point_y = rgb_parameters_.principal_point_y;
229 setRGBFocalLength (
const double rgb_focal_length)
231 rgb_parameters_.focal_length_x = rgb_focal_length;
232 rgb_parameters_.focal_length_y = rgb_focal_length;
243 setRGBFocalLength (
const double rgb_focal_length_x,
const double rgb_focal_length_y)
245 rgb_parameters_.focal_length_x = rgb_focal_length_x;
246 rgb_parameters_.focal_length_y = rgb_focal_length_y;
254 getRGBFocalLength (
double &rgb_focal_length_x,
double &rgb_focal_length_y)
const
256 rgb_focal_length_x = rgb_parameters_.focal_length_x;
257 rgb_focal_length_y = rgb_parameters_.focal_length_y;
269 setDepthCameraIntrinsics (
const double depth_focal_length_x,
270 const double depth_focal_length_y,
271 const double depth_principal_point_x,
272 const double depth_principal_point_y)
274 depth_parameters_ = CameraParameters (
275 depth_focal_length_x, depth_focal_length_y,
276 depth_principal_point_x, depth_principal_point_y);
286 getDepthCameraIntrinsics (
double &depth_focal_length_x,
287 double &depth_focal_length_y,
288 double &depth_principal_point_x,
289 double &depth_principal_point_y)
const
291 depth_focal_length_x = depth_parameters_.focal_length_x;
292 depth_focal_length_y = depth_parameters_.focal_length_y;
293 depth_principal_point_x = depth_parameters_.principal_point_x;
294 depth_principal_point_y = depth_parameters_.principal_point_y;
303 setDepthFocalLength (
const double depth_focal_length)
305 depth_parameters_.focal_length_x = depth_focal_length;
306 depth_parameters_.focal_length_y = depth_focal_length;
317 setDepthFocalLength (
const double depth_focal_length_x,
const double depth_focal_length_y)
319 depth_parameters_.focal_length_x = depth_focal_length_x;
320 depth_parameters_.focal_length_y = depth_focal_length_y;
328 getDepthFocalLength (
double &depth_focal_length_x,
double &depth_focal_length_y)
const
330 depth_focal_length_x = depth_parameters_.focal_length_x;
331 depth_focal_length_y = depth_parameters_.focal_length_y;
338 setupDevice (
const std::string& device_id,
const Mode& depth_mode,
const Mode& image_mode);
346 startSynchronization ();
350 stopSynchronization ();
382 signalsChanged ()
override;
388 checkImageAndDepthSynchronizationRequired ();
392 checkImageStreamRequired ();
396 checkDepthStreamRequired ();
400 checkIRStreamRequired ();
427 std::vector<std::uint8_t> color_resize_buffer_;
428 std::vector<std::uint16_t> depth_resize_buffer_;
429 std::vector<std::uint16_t> ir_resize_buffer_;
433 processColorFrame (openni::VideoStream& stream);
436 processDepthFrame (openni::VideoStream& stream);
439 processIRFrame (openni::VideoStream& stream);
442 Synchronizer<pcl::io::openni2::Image::Ptr, pcl::io::openni2::DepthImage::Ptr > rgb_sync_;
443 Synchronizer<pcl::io::openni2::IRImage::Ptr, pcl::io::openni2::DepthImage::Ptr > ir_sync_;
448 std::string rgb_frame_id_;
449 std::string depth_frame_id_;
450 unsigned image_width_;
451 unsigned image_height_;
452 unsigned depth_width_;
453 unsigned depth_height_;
455 bool image_required_;
456 bool depth_required_;
460 boost::signals2::signal<sig_cb_openni_image>* image_signal_;
461 boost::signals2::signal<sig_cb_openni_depth_image>* depth_image_signal_;
462 boost::signals2::signal<sig_cb_openni_ir_image>* ir_image_signal_;
463 boost::signals2::signal<sig_cb_openni_image_depth_image>* image_depth_image_signal_;
464 boost::signals2::signal<sig_cb_openni_ir_depth_image>* ir_depth_image_signal_;
465 boost::signals2::signal<sig_cb_openni_point_cloud>* point_cloud_signal_;
466 boost::signals2::signal<sig_cb_openni_point_cloud_i>* point_cloud_i_signal_;
467 boost::signals2::signal<sig_cb_openni_point_cloud_rgb>* point_cloud_rgb_signal_;
468 boost::signals2::signal<sig_cb_openni_point_cloud_rgba>* point_cloud_rgba_signal_;
472 bool operator () (
const openni::VideoMode& mode1,
const openni::VideoMode & mode2)
const
474 if (mode1.getResolutionX () < mode2.getResolutionX ())
476 if (mode1.getResolutionX () > mode2.getResolutionX ())
478 if (mode1.getResolutionY () < mode2.getResolutionY ())
480 if (mode1.getResolutionY () > mode2.getResolutionY ())
482 return (mode1.getFps () < mode2.getFps ());
487 std::map<int, pcl::io::openni2::OpenNI2VideoMode> config2oni_map_;
495 CameraParameters rgb_parameters_;
496 CameraParameters depth_parameters_;
503 OpenNI2Grabber::getDevice ()
const
511 #endif // HAVE_OPENNI2
shared_ptr< PointCloud< PointT > > Ptr
Class containing just a reference to IR meta data.
shared_ptr< IRImage > Ptr
DeviceArray2D< uchar4 > Image
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
shared_ptr< DepthImage > Ptr
pcl::io::DepthImage DepthImage
Image interface class providing an interface to fill a RGB or Grayscale image buffer.
This class provides methods to fill a depth or disparity image.
shared_ptr< OpenNI2Device > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr