Tech Tips

  1. 要素技術
  2. 4401 view

[PCL][Python][CPP]Python PCL (Point Cloud Library)のインストールとサンプル実行

概要

PCL(点群処理ライブラリ)のが出たということで触って見た。
まだ python pcl でできる部分は少ないみたい。

Env

Linux ubuntu 3.8.0-29-generic #42~precise1-Ubuntu SMP Wed Aug 14 15:31:16 UTC 2013 i686 i686 i386 GNU/Linux

インストール

PCL

# install add-apt-repository
$ sudo apt-get install software-properties-common python-software-properties
# add repository for pcl
$ sudo add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
$ sudo apt-get update
$ sudo apt-get install libpcl-all

Pythonバインディング

$ sudo apt-get install python-pip
# install Python.h
$ sudo apt-get install python-dev
# install Cython.Distutils
$ sudo pip install Cython
$ sudo pip install numpy
# Install python binding
$ git clone https://github.com/strawlab/python-pcl.git
$ python setup.py install

Run Sample

Pythonバインディングサンプル

import pcl
p = pcl.PointCloud()
p.from_file("test_pcd.pcd")
fil = p.make_statistical_outlier_filter()
fil.set_mean_k (50)
fil.set_std_dev_mul_thresh (1.0)
fil.filter().to_file("inliers.pcd")
$ wget http://www.pointclouds.org/assets/files/presentations/IROS2011-PCL-tutorial-data.zip
$ unzip IROS2011-PCL-tutorial-data.zip
$ cp data/robot/raw_0.pcd ./test_pcd.pcd
$ python pcltest.py

実行結果の確認

pcd形式のデータをviewerを作って確認する。
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>

int user_data;

void
viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
{
    viewer.setBackgroundColor (1.0, 0.5, 1.0);
    pcl::PointXYZ o;
    o.x = 1.0;
    o.y = 0;
    o.z = 0;
    viewer.addSphere (o, 0.25, "sphere", 0);
    std::cout << "i only run once" << std::endl;

}

void
viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
{
    static unsigned count = 0;
    std::stringstream ss;
    ss << "Once per viewer loop: " << count++;
    viewer.removeShape ("text", 0);
    viewer.addText (ss.str(), 200, 300, "text", 0);

    //FIXME: possible race condition here:
    user_data++;
}

int
main ()
{
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
    pcl::io::loadPCDFile ("test_pcd.pcd", *cloud);

    pcl::visualization::CloudViewer viewer("Cloud Viewer");

    //blocks until the cloud is actually rendered
    viewer.showCloud(cloud);

    //use the following functions to get access to the underlying more advanced/powerful
    //PCLVisualizer

    //This will only get called once
    viewer.runOnVisualizationThreadOnce (viewerOneOff);

    //This will get called once per visualization iteration
    viewer.runOnVisualizationThread (viewerPsycho);
    while (!viewer.wasStopped ())
    {
    //you can also do cool processing here
    //FIXME: Note that this is running in a separate thread from viewerPsycho
    //and you should guard against race conditions yourself...
    user_data++;
    }
    return 0;
}
$ vim CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(cloud_viewer)

find_package(PCL 1.2 REQUIRED)

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

add_executable (cloud_viewer cloud_viewer.cpp)
target_link_libraries (cloud_viewer ${PCL_LIBRARIES})
$ cmake .
$ make
$ export LC_ALL=C
$ ./cloud_viewer

元のPCD

pcl-viewer1

変換後のPCD

pcl-viewer2

要素技術の最近記事

  1. Udacity Self-Driving Car Engineer Nanodegree …

  2. TF-Agents で独自の環境を利用する方法

  3. Amazon Rekognition Video を使って動画内の顔検出と境界ボックスの描…

  4. [触ってみた]Microsoft Quantum Development Kit

  5. Tensorboardを使ってニューラルネットワークと学習の状況を可視化する

関連記事

PAGE TOP