端末で次のように操作する。
◆ Ubuntu の場合の操作手順
sudo apt-get update sudo apt-get -yV upgrade sudo shutdown -r now
sudo apt -y update sudo apt -y install libpcl-1.7-all
ここで行うこと:「Writing PCD Cloud data to PCD files」を動作させて、libpcl のインストールがうまく行ったことを確認する.
出展: http://www.pointclouds.org/documentation/tutorials/writing_pcd.php#writing-pcd
コンパイル手順の説明 http://www.pointclouds.org/documentation/tutorials/using_pcl_pcl_config.php#using-pcl-pcl-config
#include<iostream> #include<pcl/io/pcd_io.h> #include<pcl/point_types.h> int main (int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ> cloud; // Fill in the cloud data cloud.width = 5; cloud.height = 1; cloud.is_dense = false; cloud.points.resize (cloud.width * cloud.height); for (size_t i = 0; i < cloud.points.size (); ++i) { cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f); cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f); cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f); } pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud); std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl; for (size_t i = 0; i < cloud.points.size (); ++i) std::cerr << " " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl; return (0); }
cmake_minimum_required(VERSION 2.8) project(pcd_write) find_package(PCL 1.2 REQUIRED) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) add_executable (pcd_write pcd_write.cpp) target_link_libraries (pcd_write ${PCL_LIBRARIES})
cd /tmp mkdir build cd build cmake ..
make
./pcd_write
付属の付属のソースコード visualization/tools/openni_viewer_simple.cpp をコンパイルしてみる
出展: http://www.pointclouds.org/documentation/tutorials/openni_grabber.php#openni-grabber
#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; }
/tmp/CMakeLists.txt
cmake_minimum_required(VERSION 2.8) project(openni_viewer_simple) find_package(PCL 1.2 REQUIRED) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) add_executable (openni_viewer_simple openni_viewer_simple.cpp) target_link_libraries (openni_viewer_simple ${PCL_LIBRARIES})
cd /tmp mkdir build cd build cmake ..
make
./openni_viewer_simple
最初、何も映らなくて不安になるが、 マウスを使って視野を回転させると、データが見える(はず)。 このとき Kinect の緑のランプは点滅状態
付属の付属のソースコード visualization/tools/openni_viewer_simple.cpp をコンパイルしてみる
出展: http://www.pointclouds.org/documentation/tutorials/openni_grabber.php#openni-grabber
/tmp/openni_grabber.cpp
#include<pcl/point_cloud.h> #include<pcl/point_types.h> #include<pcl/io/openni_grabber.h> #include<pcl/common/time.h> #include<pcl/visualization/cloud_viewer.h> class SimpleOpenNIProcessor { public: SimpleOpenNIProcessor() : viewer("") {}; void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud) { static unsigned count = 0; static double last = pcl::getTime (); if (!viewer.wasStopped()) viewer.showCloud (cloud); if (++count == 30) { double now = pcl::getTime (); std::cout << "distance of center pixel :" << cloud->points [(cloud->width >> 1) * (cloud->height + 1)].z << " mm. Average framerate: " << double(count)/double(now - last) << " Hz" << std::endl; count = 0; last = now; } } void run () { // create a new grabber for OpenNI devices pcl::Grabber* interface = new pcl::OpenNIGrabber(); // make callback function from member function boost::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f = boost::bind (&SimpleOpenNIProcessor::cloud_cb_, this, _1); // connect callback function for desired signal. In this case its a point cloud with color values boost::signals2::connection c = interface->registerCallback (f); // start receiving point clouds interface->start (); // wait until user quits program with Ctrl-C, but no busy-waiting -> sleep (1); while (!viewer.wasStopped()) { boost::this_thread::sleep (boost::posix_time::seconds (1)); } // stop the grabber interface->stop (); } pcl::visualization::CloudViewer viewer; }; int main () { SimpleOpenNIProcessor v; v.run (); return (0); }
/tmp/CMakeLists.txt
cmake_minimum_required(VERSION 2.8) 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})
cd /tmp mkdir build cd build cmake ..
make
./openni_grabber