前回
↓
点群処理の救世主!! ubuntuでPCL1.8 を使う - ayuge-sunのブログ
やりたいこと
- ubuntuでPCL(point cloud library)1.8をbuildする(目的1)
- HDL-64E(HDL-32E)から得られるpcapファイルを処理する(目的2)
- ライブラリに実装されているGPUの機能を用いて点群処理を高速化する(目的3)
動作環境
※本投稿では、主に目的2について動作チェックを行う。
1 HDL-64E(HDL-32E)から得られるpcapファイルを処理する
ファイルの準備
データ処理したいLIDARのストリーミングデータ(.pcap)を用意する。 また、LIDAR固有のキャリブレーションファイル(.xml)を用意する。
手元にLIDARは無いけど動作確認はしたいという人は、以下のサイトよりダウンロードしてくる。
https://midas3.kitware.com/midas/community/29
↑サイトの様子
本投稿では、サイト内の「HDL32-V2_Tunnel.pcap」をDownloadフォルダにダウンロードしたとして話を進める。
作業用ディレクトリを用意
cd ~/Documents mkdir pcap_sample cd pcap_sample
プログラムの用意
参考:http://pointclouds.org/documentation/tutorials/hdl_grabber.php
pcap_sample
フォルダ内に、hdl_viewer_simple.cppというファイルを新規作成し、以下のコードを貼り付ける。
#include <pcl/point_cloud.h> #include <pcl/point_types.h> #include <pcl/io/hdl_grabber.h> #include <pcl/visualization/point_cloud_color_handlers.h> #include <pcl/visualization/cloud_viewer.h> #include <pcl/console/parse.h> using namespace std; using namespace pcl; using namespace pcl::console; using namespace pcl::visualization; class SimpleHDLViewer { public: typedef pcl::PointCloud<pcl::PointXYZI> Cloud; typedef typename Cloud::ConstPtr CloudConstPtr; SimpleHDLViewer (Grabber& grabber, pcl::visualization::PointCloudColorHandler<pcl::PointXYZI> &handler) : cloud_viewer_ (new pcl::visualization::PCLVisualizer ("PCL HDL Cloud")), grabber_ (grabber), handler_ (handler) { } void cloud_callback (const CloudConstPtr& cloud) { boost::mutex::scoped_lock lock (cloud_mutex_); cloud_ = cloud; } void run () { cloud_viewer_->addCoordinateSystem (3.0); cloud_viewer_->setBackgroundColor (0, 0, 0); cloud_viewer_->initCameraParameters (); cloud_viewer_->setCameraPosition (0.0, 0.0, 30.0, 0.0, 1.0, 0.0, 0); cloud_viewer_->setCameraClipDistances (0.0, 50.0); boost::function<void (const CloudConstPtr&)> cloud_cb = boost::bind ( &SimpleHDLViewer::cloud_callback, this, _1); boost::signals2::connection cloud_connection = grabber_.registerCallback ( cloud_cb); grabber_.start (); while (!cloud_viewer_->wasStopped ()) { CloudConstPtr cloud; // See if we can get a cloud if (cloud_mutex_.try_lock ()) { cloud_.swap (cloud); cloud_mutex_.unlock (); } if (cloud) { handler_.setInputCloud (cloud); if (!cloud_viewer_->updatePointCloud (cloud, handler_, "HDL")) cloud_viewer_->addPointCloud (cloud, handler_, "HDL"); cloud_viewer_->spinOnce (); } if (!grabber_.isRunning ()) cloud_viewer_->spin (); boost::this_thread::sleep (boost::posix_time::microseconds (100)); } grabber_.stop (); cloud_connection.disconnect (); } boost::shared_ptr<pcl::visualization::PCLVisualizer> cloud_viewer_; pcl::Grabber& grabber_; boost::mutex cloud_mutex_; CloudConstPtr cloud_; pcl::visualization::PointCloudColorHandler<pcl::PointXYZI> &handler_; }; int main (int argc, char ** argv) { std::string hdlCalibration, pcapFile; parse_argument (argc, argv, "-calibrationFile", hdlCalibration); parse_argument (argc, argv, "-pcapFile", pcapFile); pcl::HDLGrabber grabber (hdlCalibration, pcapFile); pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZI> color_handler ("intensity"); SimpleHDLViewer v (grabber, color_handler); v.run (); return (0); }
さらに、pcap_sample
フォルダ内に、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 hdl_viewer_simple.cpp) target_link_libraries (openni_grabber ${PCL_LIBRARIES})
cmake
pcap_sample
フォルダ内で以下のコマンドを実行。
cmake . make -j4
フォルダ内に実行ファイルopenni_grabberが出来上がる。
実行
pcap_sample
フォルダ内で以下のコマンドを実行。
./openni_grabber -pcapFile ~/Downloads/HDL32-V2_Tunnel.pcap
↑実行した様子
※LIDARがHDL-64Eである場合、キャリブレーションファイルがないとおかしな点群が表示されてしまう。実行時のコマンドは以下のようにするとよい。
./openni_grabber -pcapFile <pcap format file> -calibrationFile <xml format file>
次回、動作チェック後編。次の投稿に乞うご期待!!!