python-pcl v1.0

Python Bindings to the Point Cloud Library

Contents

Fork me on GitHub

Introduction

This is a small python binding to the pointcloud library. Currently, the following parts of the API are wrapped (all methods operate on PointXYZ) point types

  • I/O and integration; saving and loading PCD files
  • segmentation
  • SAC
  • smoothing
  • filtering

The code tries to follow the Point Cloud API, and also provides helper function for interacting with numpy. For example (from tests/test.py)

import pcl
p = pcl.PointCloud()
p.from_array(np.array([[1,2,3],[3,4,5]], dtype=np.float32)))
seg = self.p.make_segmenter()
seg.set_model_type(pcl.SACMODEL_PLANE)
seg.set_method_type(pcl.SAC_RANSAC)
indices, model = seg.segment()

or, for smoothing

import pcl
p = pcl.PointCloud()
p.from_file("C/table_scene_lms400.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")

More samples can be found in the examples directory, and in the unit tests.

This work was supported by Strawlab.

Requirements

This release has been tested with

  • pcl 1.5.1
  • Cython 0.16

A note about types

Point Cloud is a heavily templated API, and consequently mapping this into python using Cython is challenging.

It is written in Cython, and implements enough hard bits of the API (from Cythons perspective, i.e the template/smart_ptr bits) to provide a foundation for someone wishing to carry on.

API Documentation

pcl.PointCloud Represents a class of points, supporting the PointXYZ type.
pcl.Segmentation Segmentation class for Sample Consensus methods and models
pcl.SegmentationNormal Segmentation class for Sample Consensus methods and models that require the
pcl.StatisticalOutlierRemovalFilter Filter class uses point neighborhood statistics to filter outlier data.
pcl.MovingLeastSquares Smoothing class which is an implementation of the MLS (Moving Least Squares)
pcl.PassThroughFilter Passes points in a cloud based on constraints for one particular field of the point type
pcl.VoxelGridFilter Assembles a local 3D grid over a given PointCloud, and downsamples + filters the data.

For deficiencies in this documentation, please consule the PCL API docs, and the PCL tutorials.

class pcl.MovingLeastSquares

Smoothing class which is an implementation of the MLS (Moving Least Squares) algorithm for data smoothing and improved normal estimation.

reconstruct(self)

Apply the smoothing according to the previously set values and return a new pointcloud

set_polynomial_fit(self, int fit)

Sets whether the surface and normal are approximated using a polynomial, or only via tangent estimation.

set_polynomial_order(self, bool order)

Set the order of the polynomial to be fit.

set_search_radius(self, double radius)

Set the sphere radius that is to be used for determining the k-nearest neighbors used for fitting.

class pcl.PassThroughFilter

Passes points in a cloud based on constraints for one particular field of the point type

filter(self)

Apply the filter according to the previously set parameters and return a new pointcloud

set_filter_field_name(self, char *field_name)
set_filter_limits(self, float filter_min, float filter_max)
class pcl.PointCloud

Represents a class of points, supporting the PointXYZ type.

extract(self, pyindices, bool negative=False)

Given a list of indices of points in the pointcloud, return a new pointcloud containing only those points.

from_array(self, ndarray arr)

Fill this object from a 2D numpy array (float32)

from_file(self, char *f)

Fill this pointcloud from a file (a local path). Only pcd files supported currently.

from_list(self, _list)

Fill this pointcloud from a list of 3-tuples

get_point(self, int row, int col)

Return a point (3-tuple) at the given row/column

height

property containing the height of the point cloud

is_dense

property containing whether the cloud is dense or not

make_moving_least_squares(self)

Return a pcl.MovingLeastSquares object with this object set as the input-cloud

make_passthrough_filter(self)

Return a pcl.PassThroughFilter object with this object set as the input-cloud

make_segmenter(self)

Return a pcl.Segmentation object with this object set as the input-cloud

make_segmenter_normals(self, int ksearch=-1, double searchRadius=-1.0)

Return a pcl.SegmentationNormal object with this object set as the input-cloud

make_statistical_outlier_filter(self)

Return a pcl.StatisticalOutlierRemovalFilter object with this object set as the input-cloud

make_voxel_grid_filter(self)

Return a pcl.VoxelGridFilter object with this object set as the input-cloud

resize(self, int x)
size

property containing the number of points in the point cloud

to_array(self)

Return this object as a 2D numpy array (float32)

to_file(self, char *f, bool ascii=True)

Save this pointcloud to a local file. Only saving to binary or ascii pcd is supported

to_list(self)

Return this object as a list of 3-tuples

width

property containing the width of the point cloud

class pcl.Segmentation

Segmentation class for Sample Consensus methods and models

segment(self)
set_distance_threshold(self, float d)
set_method_type(self, int m)
set_model_type(self, SacModel m)
set_optimize_coefficients(self, bool b)
class pcl.SegmentationNormal

Segmentation class for Sample Consensus methods and models that require the use of surface normals for estimation.

Due to Cython limitations this should derive from pcl.Segmentation, but is currently unable to do so.

segment(self)
set_axis(self, double ax, double ay, double az)
set_distance_threshold(self, float d)
set_eps_angle(self, double ea)
set_max_iterations(self, int i)
set_method_type(self, int m)
set_model_type(self, SacModel m)
set_normal_distance_weight(self, float f)
set_optimize_coefficients(self, bool b)
set_radius_limits(self, float f1, float f2)
class pcl.StatisticalOutlierRemovalFilter

Filter class uses point neighborhood statistics to filter outlier data.

filter(self)

Apply the filter according to the previously set parameters and return a new pointcloud

set_mean_k(self, int k)

Set the number of points (k) to use for mean distance estimation.

set_negative(self, bool negative)

Set whether the indices should be returned, or all points except the indices.

set_std_dev_mul_thresh(self, double std_mul)

Set the standard deviation multiplier threshold.

class pcl.VoxelGridFilter

Assembles a local 3D grid over a given PointCloud, and downsamples + filters the data.

filter(self)

Apply the filter according to the previously set parameters and return a new pointcloud

set_leaf_size(self, float x, float y, float z)

Set the voxel grid leaf size.

Contents