python点云处理模块_python版本的点云数据处理库

一、Open3D

A Modern Library for 3D Data Processing,Intel出品,MIT协议。

Open3D是一个支持3D数据处理软件快速开发的开源库。Open3D使用C++和Python公开了一组精心选择的数据结构和算法。后端经过高度优化,并设置为并行化。Open3D的依赖项较少,可在不同的平台上编译与布置。

Open3D侧重于三维数据的可视化与整体处理算法。想学习的同学可百度“Open3D学习计划”。

安装:pip install open3d 或者 pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple open3d

分享给有需要的人,代码质量勿喷。

importopen3daso3d

importnumpyasnp

frommatplotlibimportpyplotasplt

# read PC

pcd = o3d.io.read_point_cloud("F:/test.pcd")

# # write PC

# o3d.io.write_point_cloud("F:/newFile.pcd",pcd)

# DBSCAN

witho3d.utility.VerbosityContextManager(o3d.utility.VerbosityLevel.Debug)ascm:

labels = np.array(pcd.cluster_dbscan(eps=0.1, min_points=10, print_progress=True))

max_label = labels.max()

print(f"point cloud has{max_label +1}clusters")

colors = plt.get_cmap("tab20")(labels / (max_labelifmax_label >0else1))

colors[labels <0] =0

pcd.colors = o3d.utility.Vector3dVector(colors[:, :3])

# 可视化

o3d.visualization.draw_geometries([pcd],width=910,height=540)

c4e065a33da5

3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK),MIT协议。

PyVista具有可视化工具包(VTK)的高级API,空间数据集的网格数据结构和过滤方法,使3D绘图变得简单,可用于大型/复杂数据几何.

PyVista(以前称为vtki)是可视化工具包(VTK)的帮助程序模块,它通过NumPy和直接数组访问采用了与VTK接口不同的方法。该软件包提供了Pythonic的,文档齐全的界面,该界面公开了VTK强大的可视化后端,以促进对空间参考数据集的快速原型制作,分析和可视化集成。该模块可用于演示文稿和研究论文的科学绘图,以及其他与网格相关的Python模块的支持模块。

PyVista侧重于可视化。

安装:pip install pyvista 或者 pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pyvista

分享给有需要的人,代码质量勿喷。

importpyvistaaspv

mesh = pv.read('F:/test.vtk')

mesh.plot(screenshot='F:/test.vtk.png')

c4e065a33da5

/* ************************************************** 挺好的 *************************************************************** */

PCL(Point Cloud Library)是主要用于点云(二三维图像也可)的独立、强大的开源项目,BSD协议,可免费用于商业和研究用途。

PCL是点云数据处理的王者库,近乎全能,可视化、读写、算法(!!!)。

但是,python-pcl安装较为麻烦!!!建议谷歌或百度。

pclpy是python-pcl的姊妹库吧,安装很方便,算法接口啥的也挺全的,而且,支持las。同时存在某些限制,比如正在开发中,API和功能测试也许会不稳定,只支持Windows和python 3.6 x64。

安装:pip install pclpy 或者 pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pclpy

分享给有需要的人,代码质量勿喷。

importpclpy

frompclpyimportpcl

# 读

pc=pclpy.pcl.PointCloud.PointXYZRGBA()

pcl.io.loadPCDFile('F:/test.pcd',pc)

# 显示

viewer=pcl.visualization.PCLVisualizer('Point Cloud viewer')

viewer.addPointCloud(pc)

while(notviewer.wasStopped()):

viewer.spinOnce(100)

c4e065a33da5

pyntcloud是一个Python 3.x库,利用Python科学堆栈的强大功能处理3D点云。

pyntcloud侧重于点云数据处理,例如读写(支持las)、属性、滤波、数据结构组织、构建体素、抽稀、RANSAC等。与Open3D、PyVista等库衔接较好。

安装:pip install pyntcloud 或者 pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pyntcloud

分享给有需要的人,代码质量勿喷。

frompyntcloudimportPyntCloud

importopen3daso3d

# io

cloud = PyntCloud.from_file("F:/test.ply")

# structures

kdtree_id = cloud.add_structure("kdtree")

# neighbors

k_neighbors = cloud.get_neighbors(k=5, kdtree=kdtree_id)

# scalar_fields

ev = cloud.add_scalar_field("eigen_values", k_neighbors=k_neighbors)

# filters

f = cloud.get_filter("BBOX", min_x=0.1, max_x=0.8)

# FROM Open3D

original_triangle_mesh = o3d.io.read_triangle_mesh("F:/test.ply")

cloud = PyntCloud.from_instance("open3d", original_triangle_mesh)

# TO Open3D

cloud = PyntCloud.from_file("F:/test.ply")

converted_triangle_mesh = cloud.to_instance("open3d", mesh=True)# mesh=True by default

/* *************************************************  liblas系列  *************************************************** */

libLAS是一个C/C++/Python库(接触的第一个点云处理库),用于读写LAS格式的点云。libLAS支持ASPRS LAS格式规范版本:1.0、1.1、1.2和1.3(基本支持)。虽然libLAS已经被 PDAL / Laspy 取代,但不可否认,它是一个很nice的库。

libLAS库侧重于点云的读写、修改编辑处理。

安装:pip install liblas  或者  pip install -i https://pypi.tuna.tsinghua.edu.cn/simple liblas

分享给有需要的人,代码质量勿喷。

importliblas

fromliblasimportfile

fromliblasimportheader

# 读

f=file.File('F:/test.las',mode='r')

# 头文件

lasHeader = f.header

print('主版本号:'+ str(lasHeader.major_version))

print('副版本号:'+ str(lasHeader.minor_version))

print('最小值:%f,%f,%f'% (lasHeader.min[0],lasHeader.min[1],lasHeader.min[2]))

print('最大值:%f,%f,%f'% (lasHeader.max[0],lasHeader.max[1],lasHeader.max[2]))

print('比例:%f,%f,%f'% (lasHeader.scale[0],lasHeader.scale[1],lasHeader.scale[2]))

print('偏移量:%f,%f,%f'% (lasHeader.offset[0],lasHeader.offset[1],lasHeader.offset[2]))

print('点云数量:%d'% (lasHeader.point_records_count))

# 遍历点

forpointinf:

# point = f[0]

print('x=%f, y=%f, z=%f, intensity=%d, PointsourceID=%d, GPStime=%f,

Red=%d, Green=%d, Blue=%d, Classification=%d, UserData=%d'

% (point.x, point.y, point.z,

point.intensity, point.point_source_id, point.raw_time,

point.color.red, point.color.green, point.color.blue,

point.classification, point.user_data))

# 写

las_header = header.Header()

las_header.dataformat_id =1

las_header.minor_version =2

fw = file.File('F:/new.las', mode='w', header=las_header)

pt = liblas.point.Point()

foriinrange(10):

pt.x =118.0+i

pt.y =532.0+i

pt.z =112.0+i

fw.write(pt)

fw.close()

print('ok666')

libLAS的升级版。PDAL(Point Data Abstraction Library)是一个C/C ++开源库,用于转换和处理点云数据。尽管库中许多重点工具源于LiDAR,但它不限于LiDAR数据。

安装:pip install PDAL(没成功,郁闷)

兼容 libLAS 的点云处理python库,与 libLAS算是一家吧。Laspy是一个用于读取、修改和创建LAS LiDAR文件的python库。对LAZ的支持仅限于1.0-1.3版本。Laspy与Python 2.6+和3.5+兼容。Laspy包含一组命令行工具,可用于执行基本文件操作,例如格式转换和验证以及比较LAS文件。

安装:pip install laspy 或者 pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple laspy

分享给有需要的人,代码质量勿喷。

importnumpyasnp

importlaspy

fromlaspy.fileimportFile

# 读

f = File('F:/test.las', mode='r')

# 头

lasHeader = f.header

print('主版本号:'+ str(lasHeader.major_version))

print('副版本号:'+ str(lasHeader.minor_version))

print('最小值:%f,%f,%f'% (lasHeader.min[0],lasHeader.min[1],lasHeader.min[2]))

print('最大值:%f,%f,%f'% (lasHeader.max[0],lasHeader.max[1],lasHeader.max[2]))

print('比例:%f,%f,%f'% (lasHeader.scale[0],lasHeader.scale[1],lasHeader.scale[2]))

print('偏移量:%f,%f,%f'% (lasHeader.offset[0],lasHeader.offset[1],lasHeader.offset[2]))

print('点云数量:%d'% (lasHeader.point_records_count))

# 遍历点

points = f.points

defscaled_x_dimension(las_file):

x_dimension = las_file.X

scale = las_file.header.scale[0]

offset = las_file.header.offset[0]

return(x_dimension*scale + offset)

foriinrange(66,666):

print('x=%f, y=%f, z=%f, intensity=%d, GPStime=%f, Classification=%d, UserData=%d,

Red=%d, Green=%d, Blue=%d'

% (scaled_x_dimension(f)[i], f.y[i],f.z[i],

f.intensity[i], f.gps_time[i],f.classification[i],f.user_data[i],

f.red[i],f.green[i], f.blue[i]))

# 筛选路面点

c11 = f.Classification ==11

# 保存路面点为新文件

outFile = File('F:/output.las', mode='w', header=f.header)

outFile.points = f.points[c11]

outFile.close()

print("ok")

/* ************************************************************** 其它 *************************************************** */

plyfile用于读写ply文件。

安装:pip install plyfile 或者 pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple plyfile

Point Cloud Utils (pcu) - A Python library for common tasks on 3D point clouds

挺实用。

安装:pip install git+git://github.com/fwilliams/point-cloud-utils

pptk(Point Processing Toolkit)是用于可视化和处理二三维点云的python包。目前,其具有以下功能:

(1)点云查看,可接受任何3列numpy数组作为输入;

(2)基于Octree的LOD点云渲染可视化;

(3)支持点选,用于检查和注释点数据;

(4)并行化的点KD-tree;

(5)基于点云邻域PCA的法线估计。

安装:pip install pptk 或者 pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pptk

分享给有需要的人,代码质量勿喷。

importpptk

# Create 100 random points

xyz = pptk.rand(200,3)

# Visualize points shaded by height

v = pptk.viewer(xyz, xyz[:,2])

v.set(point_size=0.005)

c4e065a33da5

PyLidar用于从LiDAR设备中获取数据。其分为PyLidar2和PyLidar3,分别对应python2和python3版本。

安装:pip install PyLidar3

/* ************************************** 以下的已经不维护或者很久没更新了 ********************************************** */

This code is no longer maintained.

Originally designed as a proof-of-concept for reading Light Detection and Ranging (LIDAR) data in binary LAS format and converting to GIS point data formats (xyz or shapefile). Today, there are much better tools for using LIDAR in python code - this repo is for archival purposes only.

The las module implements a reader for LAS (Log ASCII Standard) well log files (LAS 2.0). For more information about this format, see the Canadian Well Logging Society web page (http://www.cwls.org/las/).

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值