Drawing Point Cloud retrieve from Kinect v2 using Point Cloud Library – part.2 with Grabber

What is Grabber?

Point Cloud Library (PCL) have some modules for input data that called “Grabber”.

  • OpenNI2Grabber
  • This module is grabber for input data from PrimeSensor based on OpenNI2.

  • HDLGrabber/VLPGrabber
  • This module is grabber for input data from Velodyne LiDAR based on Boost.Asio and PCAP.

  • RealSenseGrabber
  • This module is grabber for input data from Intel RealSense cameras based on RealSense SDK and librealsense.

PCL with Kinect v2

PCL doesn’t have grabber for input data from Kinect v2.
So, I will introduce two ways to input data from Kinect v2 based on Kinect SDK v2.

  • part.1 without Grabber
  • This method doesn’t use Grabber.
    It will manually inputting data to PCL from Kinect v2.

  • part.2 with Grabber (this article)
  • This method use Grabber.
    It will use Kinect2Grabber.


These Grabbers is implemented as class that inherits from pcl::Grabber.
You can implement original Grabber that are not included in PCL by implementing class that inherits from pcl::Grabber.

Kinect2Grabber is grabber to input data from Kinect v2 based on Kinect SDK v2.
This Grabber only depend on Kinect SDK v2. You don’t need to have other libraries to use Kinect2Grabber.*1
In addition, This Grabber has been implemented in only one header file (kinect2_grabber.h). You can use Kinect2Grabber by just include header file.

*1 You need to setting project for Kinect SDK v2 because this Grabber depend on Kinect SDK v2. The sample program uses FindKinectSDK2.cmake.

This Grabber is published in following.

Drawing Point Cloud retrieved from Kinect v2 using Point Cloud Library with Grabber

This sample program is published in following.


You need to include kinect2_grabber.h in order to use pcl::Kinect2Grabber.


#include "kinect2_grabber.h"


You will create instance of pcl::Kinect2Grabber.


// Kinect2Grabber
boost::shared_ptr<pcl::Grabber> grabber = boost::make_shared<pcl::Kinect2Grabber>();

Register Callback

You will define callback function to retrieve point cloud using pcl::Kinect2Grabber.
This callback function is called each time to retrieve point cloud of one frame.
You will write point cloud processing in here, and returns shared pointer of point cloud to outside.

Then, You will register callback function to pcl::Kinect2Grabber.
You will give function pointer to pcl::Kinect2Grabber::registerCallback().


// Retrieved Point Cloud Callback Function
pcl::PointCloud<PointType>::ConstPtr cloud;
boost::mutex mutex;
boost::function<void( const pcl::PointCloud<PointType>::ConstPtr& )> function =
    [&cloud, &mutex]( const pcl::PointCloud<PointType>::ConstPtr& ptr ){
        boost::mutex::scoped_lock lock( mutex );

        /* Point Cloud Processing */

        cloud = ptr->makeShared();


// Register Callback Function
boost::signals2::connection connection = grabber->registerCallback( function );


You will call pcl::Kinect2Grabber::start() to start retrieve point cloud.
As well, You will call pcl::Kinect2Grabber::stop() to stop retrieve point cloud.


// Start Grabber

while( !viewer->wasStopped() ){
    // Update Viewer

    boost::mutex::scoped_try_lock lock( mutex );
    if( lock.owns_lock() && cloud ){
        // Update Point Cloud
        if( !viewer->updatePointCloud( cloud, "cloud" ) ){
            viewer->addPointCloud( cloud, "cloud" );

// Stop Grabber

Execution Result

It will be real-time display Point Cloud that retrieved from Kinect v2 when running this sample program.


Leave a Reply

Your email address will not be published. Required fields are marked *