File Io 文件IO
Point cloud 点云
下面的代码读取和写入点云。
print("Testing IO for point cloud ...") sample_pcd_data = o3d.data.PCDPointCloud() pcd = o3d.io.read_point_cloud(sample_pcd_data.path) print(pcd) o3d.io.write_point_cloud("copy_of_fragment.pcd", pcd)
默认情况下,Open3D 尝试通过文件扩展名推断文件类型。支持以下点云文件类型:
Format | Description |
xyz | 每行包含 [x, y, z], x, y, z是3D坐标 |
xyzn | 每行包含 [x, y, z, nx, ny, nz], nx, ny, nz 是法线 |
xyzrgb | 每行包含[x, y, z, r, g, b], r, g, b 是[0, 1]范围的浮点数 |
pts | 第一行是点的数量. 后续行的格式为: [x, y, z, i, r, g, b], [x, y, z, r, g, b], [x, y, z, i] or [x, y z], where x, y, z, i are of type double and r, g, b are of type uint8 |
ply | See Polygon File Format http://paulbourke.net/dataformats/ply/, ply文件包含点云和三角数据 |
pcd | See Point Cloud Data http://pointclouds.org/documentation/tutorials/pcd_file_format.html |
典型的ply文件格式
Header Vertex List Face List (lists of other elements)
ply format ascii 1.0 { ascii/binary, format version number } comment made by Greg Turk { comments keyword specified, like all lines } comment this file is a cube element vertex 8 { define "vertex" element, 8 of them in file } property float x { vertex contains float "x" coordinate } property float y { y coordinate is also a vertex property } property float z { z coordinate, too } element face 6 { there are 6 "face" elements in the file } property list uchar int vertex_index { "vertex_indices" is a list of ints } end_header { delimits the end of the header } 0 0 0 { start of vertex list } 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 4 0 1 2 3 { start of face list } 4 7 6 5 4 4 0 4 5 1 4 1 5 6 2 4 2 6 7 3 4 3 7 4 0
也可以显式指定文件类型。在这种情况下,文件扩展名将被忽略。
pcd = o3d.io.read_point_cloud("../../test_data/my_points.txt", format='xyz')
Mesh
print("Testing IO for meshes ...") knot_data = o3d.data.KnotMesh() mesh = o3d.io.read_triangle_mesh(knot_data.path) print(mesh) o3d.io.write_triangle_mesh("copy_of_knot.ply", mesh)
与点云数据结构相比,网格具有定义 3D 表面的三角形。
默认情况下,Open3D 尝试通过文件扩展名推断文件类型。支持以下网格文件类型
Format | Description |
Image
下面的代码读取和写入图像。
print("Testing IO for images ...") image_data = o3d.data.JuneauImage() img = o3d.io.read_image(image_data.path) print(img) o3d.io.write_image("copy_of_Juneau.jpg", img)
jpg、png两种格式都支持。