This is a fork of the original ``pypcd`` library to support Python 3.
Pure Python module to read and write point clouds stored in the PCD file format, used by the Point Cloud Library.
You want to mess around with your point cloud data without writing C++ and waiting hours for the template-heavy PCL code to compile.
You tried to get some of the Python bindings for PCL to compile and just gave up.
It parses the PCD header and loads the data (whether in ascii,
binary or binary_compressed format) as a
Numpy structured array. It creates an
instance of the PointCloud class, containing the point cloud data as pc_data, and
some convenience functions for I/O and metadata access.
See the comments in pypcd.py for some info on the point cloud
structure.
import pypcd
# also can read from file handles.
pc = pypcd.PointCloud.from_path('foo.pcd')
# pc.pc_data has the data as a structured array
# pc.fields, pc.count, etc have the metadata
# center the x field
pc.pc_data['x'] -= pc.pc_data['x'].mean()
# save as binary compressed
pc.save_pcd('bar.pcd', compression='binary_compressed')Using pip (recommended):
pip install pypcd- Optional dependencies:
- pandas for DataFrame support
- python-lzf for compressed PCD support
From source:
git clone https://github.com/juhasch/pypcd
cd pypcd
pip install -e .Note: Downloading data assets requires git-lfs.
This library can be used with ROS sensor_msgs. You can install it using pip
or integrate it into your ROS workspace:
# Install required dependency
pip install python-lzf
# Setup in ROS workspace
cd your_workspace/src
git clone https://github.com/juhasch/pypcd
mv setup_ros.py setup.py
catkin build pypcd
source ../devel/setup.bashExample ROS usage:
import pypcd
import rospy
from sensor_msgs.msg import PointCloud2
def cb(msg):
pc = pypcd.PointCloud.from_msg(msg)
pc.save('foo.pcd', compression='binary_compressed')
# Manipulate your pointcloud
pc.pc_data['x'] *= -1
outmsg = pc.to_msg()
# Set the header
outmsg.header = msg.header
pub.publish(outmsg)
# ROS node setup
sub = rospy.Subscriber('incloud', PointCloud2)
pub = rospy.Publisher('outcloud', PointCloud2, cb)
rospy.init_node('pypcd_node')
rospy.spin()- Supports
ascii,binaryandbinary_compressedPCD formats - RGB encoding/decoding to single
float32 - Conversion to/from pandas DataFrames
- ROS PointCloud2 message conversion
- Python 3 support
- No automatic synchronization between metadata fields and
pc_data - Primary focus on unorganized point clouds (
height=1) - Limited testing for padding and multi-count fields
- [ ] Better API for common operations
- [ ] Code cleanup and modernization
- [ ] CLI for file type conversion
- [ ] Improved structured point cloud support
- [ ] Expanded test coverage
- [ ] Enhanced documentation and examples
- [ ] Better handling of padding and multicount fields
- [ ] Improved RGB support
- [ ] PLY format export
- [ ] Package data assets in PyPI
- Original code by Daniel Maturana (
[email protected]) - ROS integration code (
numpy_pc2.py) by Jon Binney under BSD license - Contributions from @wkentaro and the community
- Compressed point cloud implementation inspired by Matlab PCL
Copyright (C) 2015-2017 Daniel Maturana