How I got openni_grabber to work using only pcl and openni binaries

My Machine Specs:

– 2015 15″ MBP

– Intel i7 (8 x64 cores)

– Ubuntu 14.04.4 x84

– AMD Radeon R9 M370X

– Kinect 360 via USB2 plug from Amazon. You may have to go through a USB2 hub to get it to work (slower).

Here’s what I installed:

ROS Indigo

- $ sudo apt-get install ros-indigo-openni*
- $ sudo apt-get install ros-indigo-freenect*

– follow “Linux” install instructions for SensorKinect

 

I prefer the openni_grabber example from pointclouds.org because the points are in all white. Their example is a bit broken by default so here is a working example of the code:

CMakeLists.txt

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(openni_grabber)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (openni_grabber openni_grabber.cpp)
target_link_libraries (openni_grabber ${PCL_LIBRARIES})

openni_grabber.cpp

 #include <pcl/io/openni_grabber.h> 
 #include <pcl/visualization/cloud_viewer.h> 

 class SimpleOpenNIViewer
 {
   public:
     SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}

     void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
     {
       if (!viewer.wasStopped())
         viewer.showCloud (cloud);
     }

     void run ()
     {
       pcl::Grabber* interface = new pcl::OpenNIGrabber();

       boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
         boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);

       interface->registerCallback (f);

       interface->start ();

       while (!viewer.wasStopped())
       {
         boost::this_thread::sleep (boost::posix_time::seconds (1));
       }

       interface->stop ();
     }

     pcl::visualization::CloudViewer viewer;
 };

 int main ()
 {
   SimpleOpenNIViewer v;
   v.run ();
   return 0;
 }

Leave a comment

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