## 2012年6月30日土曜日

### Introduction

At the tutorial in SSII2012, a brief introduction to the Point Cloud Library(PCL) was provided. It is the library for processing a point cloud (i.e. 3D point group) generated by a depth sensor. The Kinect and Xtion are familiar devices as the depth sensors. Recently I bought the Xtion Pro Live. So, in this page, I describe the procedures to run a sample program in PCL with the Xtion Pro Live.

### My Environment

1. iMac
2. Processor：3.06GHz Intel Core 2 Duo
3. Mac OS X 10.7.4
4. Xcode 4.3.3

### Installation of Prerequisite Libraries

First, I installed the following packages by using macports.
1. cmake @2.8.8
2. boost  @1.49.0
3. eigen3 @3.0.5
4. flann @1.7.1
5. vtk5 @5.8.0
6. qhull @2012.1
7. libusb @1.0.9
The versions of all packages are those which port search displays. Only for libusb, the variant universal is needed. It takes a long time to compile vtk5.
Next, I downloaded binary packages of the OpenNI and Sensor from this site.
1. openni-bin-dev-macosx-v1.5.4.0.tar.bz2
2. sensor-bin-macosx-v5.1.2.1.tar.bz2
3. nite-bin-macosx-v1.5.2.21.tar.bz2
Though the NITE is not needed for installing the PCL, I installed it for future reference. Decompressing them, a script file install.sh is found for each directory. All you have to do is just as follows: At this point, preparation for installing the PCL is completed.

### Installation of Point Cloud Library (PCL)

From this site, I could download the binary package of the PCL, and install it easily. However, when compiling a sample program in PCL, the link with the dependent library failed. Probably, it's because the versions of the prerequisite libraries are different from those consistent with the binary package of the PCL. So, I decided to compile the source codes of the PCL. The file PCL-1.5.1-Source.tar.bz2 can be downloaded from this site. The way to make is here. The default place where libraries and headers are installed is /usr/local.

### Execution of Sample Program

The tool cmake is recommended for compiling the program including PCL. In this page, I show how to compile it on the Xcode4.3.3.

#### creation of new project

I create a new project as Command Line Tool.

#### adding of a sample program

I added this file to the project.

#### <![CDATA[ #include <pcl/io/openni_grabber.h> #include <pcl/visualization/cloud_viewer.h> #ifdef _WIN32 # define sleep(x) Sleep((x)*1000) #endif 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; } ]]> setting for compilation

 -lpcl_common -lpcl_visualization -lboost_thread-mt -lpcl_io -lpcl_filters 
 /usr/local/include/pcl-1.5/ /opt/local/include /opt/local/include/eigen3/ /usr/include/ni/ /opt/local/include/vtk-5.8/ 
Library Search Paths:
 /usr/local/lib /opt/local/lib 

#### execution

When executing the project after connecting with the Xtion Pro Live, the following error occurred.

 Open failed: File not found! node depth problems node image problems node ir problems 

This site tells us that
• create a new directory /etc/primesense
• copy the following file into the directory
OpenNI-Bin-Dev-MacOSX-v1.5.4.0/Samples/Config/SamplesConfig.xml
After doing so, I got the same error. I ran grep to the file PCL-1.5.1-Source/io/src/openni_camera/openni_device.cpp, and found two places where SamplesConfig.xml must exist:
• /etc/openni/SamplesConfig.xml
• /etc/primesense/SamplesConfig.xml
Therefore, I also copied the SamplesConfig.xml into the directory /etc/openni/. Then, the program works well except for the following warning:
 node ir problems 

### Unsolved Issues

In the case of Debug mode, the program works well. But, in the case of Release mode, it encounters the segmentation fault.