本节将介绍采用Python语言的点云处理技术-Open3D开源库:支持点云的读写、可视化、重建和配准等处理、3D机器学习等
Open3D 第一节 |
核心功能如下:
- 3D data structures
- 3D data processing algorithms
- Scene reconstruction
- Surface alignment
- 3D visualization
- Physically based rendering (PBR)
- 3D machine learning support with PyTorch and TensorFlow
- GPU acceleration for core 3D operations
- Available in C++ and Python
安装
Open3D 官网、官方教程、GitHub网址如下:
- http://www.open3d.org/
- http://www.open3d.org/docs/release/
- https://github.com/isl-org/Open3D
通过执行以下命令安装
# install
pip3 install open3d -i https://pypi.tuna.tsinghua.edu.cn/simple
# verify installation
python -c "import open3d as o3d; print(o3d.__version__)"
读取、写入与可视化
Open3D支持点云(point cloud)、网格(mesh)、图像(RGB-D)三种类型的数据处理。
点云(point cloud)
- 支持xyz、xyzn、xyzrgb、pts、ply、pcd等格式
;采用read_point_cloud
函数读取点云,可根据后缀判断文件类型;采用draw_geometries
函数进行可视化
# 加载
import open3d as o3d
import numpy as np
# 读取点云、可视化
pc = o3d.io.read_point_cloud("./bunny/bunny.xyz")
# 可视化
o3d.visualization.draw_geometries([pc], window_name = "bunny",
width = 900, height = 800)
# 显示点数与点坐标
print(pc)
print(np.asarray(pc.points))
# 写入/保存
o3d.io.write_point_cloud("./bunny/bunny_output.pcd", pc)
网格(mesh):
- 支持ply、stl、obj、off、gltf/glb的格式;采用
read_triangle_mesh
函数读取
# 读取网格
mesh = o3d.io.read_triangle_mesh("./bunny/bunny.ply")
# 可视化
o3d.visualization.draw_geometries([mesh], mesh_show_wireframe = True) # True 显示网格线
# 显示三角形个数
o3d.visualization.draw_geometries([mesh], width = 900, height = 800,
mesh_show_wireframe = True) # True 显示网格线
# 写入
o3d.io.write_triangle_mesh("./bunny/bunny_output.ply", mesh)
图像(RGB-D):
- 支持img、png等格式;采用
read_image
函数读取
# 图像读写
img = o3d.io.read_image("./bunny/bunny.jpg")
o3d.visualization.draw_geometries([img])
print(img) # 显示图片大小
print(np.asarray(img))
img = o3d.io.write_image("./bunny/bunny_output.png", img)
总结
本节介绍采用开源点云处理库Open3D进行点云数据的读写与简单可视化