LoginSignup
16
18

More than 3 years have passed since last update.

Point Cloud Libraryのインストール方法 ( Ubuntu 18.04.2, PCL 1.8.1 )

Last updated at Posted at 2018-04-14

概要

3D点群処理ライブラリ、Point Cloud LibraryのUbuntu 18.04.2への導入方法について

インストール

公式サイトのインストール方法は古く、この方法ではインストール出来ません。
次のコマンドでインストール出来ます
(最新版は自身でコンパイルする必要があります)

$ sudo apt install libpcl-dev

このコマンドによってインストールされるPCLのバージョンや、依存パッケージは以下のコマンドで確認出来ます。

$ apt show libpcl-dev
Package: libpcl-dev
Version: 1.8.1+dfsg1-2ubuntu2.18.04.1
Priority: extra
Section: universe/libdevel
Source: pcl
Origin: Ubuntu
... 以下略 ...

2019/05/13現在、1.8.1がインストールされます。

またプロジェクトのビルドにcmakeを使うため、それもインストールします。

$ sudo apt install cmake

動作確認

動作確認のため、公式サイトにあるチュートリアルを動かしてみます。

作業用フォルダを作成し移動します。

$ mkdir pcl_test
$ cd pcl_test

pcd_write.cppCMakeLists.txtを作成します。

pcd_write.cpp
#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);
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

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})

ビルド用ディレクトリを作成し、ビルドします。

$ mkdir build
$ cd build
$ cmake ..
$ make

実行します。

$ ./pcd_write 
Saved 5 data points to test_pcd.pcd.
    0.352222 -0.151883 -0.106395
    -0.397406 -0.473106 0.292602
    -0.731898 0.667105 0.441304
    -0.734766 0.854581 -0.0361733
    -0.4607 -0.277468 -0.916762

Make時に下記のエラーが出た場合

/usr/bin/ld: cannot find -lvtkproj4

次のようにシンボリックリンクを張ることで回避できます。

$ sudo ln -s /usr/lib/x86_64-linux-gnu/libvtkCommonCore-6.2.so /usr/lib/libvtkproj4.so

おまけ

PCDファイルの作成には、Blenderのアドオンを使用しました。

Extensions:2.6/Py/Scripts/Import-Export/Point Cloud Data IO - BlenderWiki
git.blender.org - blender-addons-contrib.git/tree - io_points_pcd/

Ubuntuにapt install blenderでインストールした場合、アドオンは/usr/share/blender/scripts/addons/にありました。

アドオンのディレクトリを作成し、3つの.pyファイルをダウンロードします。

$ mkdir io_points_pcd && cd io_points_pcd
$ wget https://git.blender.org/gitweb/gitweb.cgi/blender-addons-$contrib.git/blob_plain/HEAD:/io_points_pcd/__init__.py
$ wget https://git.blender.org/gitweb/gitweb.cgi/blender-addons-contrib.git/blob_plain/HEAD:/io_points_pcd/pcd_utils.py
$ wget https://git.blender.org/gitweb/gitweb.cgi/blender-addons-contrib.git/blob_plain/HEAD:/io_points_pcd/pcdparser.py

これでPCDファイルのインポートとPCD形式でのエクスポートが可能となります。

参考

16
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
18