Open3D File Io 文件IO

简介: Open3D File Io 文件IO

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文件包含点云和三角数据

典型的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两种格式都支持。

相关文章
|
22天前
|
存储 Go C#
【.NET Core】深入理解IO之File类
【.NET Core】深入理解IO之File类
33 6
|
18天前
|
存储 缓存 Unix
【嵌入式软件工程师面经】Linux文件IO
【嵌入式软件工程师面经】Linux文件IO
21 1
|
22天前
|
存储 安全 Unix
【.Net Core】深入理解IO之文件和目录
【.Net Core】深入理解IO之文件和目录
30 4
|
21天前
|
Java
io读两个文件,生成list 排重后写本地文件(Java)
io读两个文件,生成list 排重后写本地文件(Java)
13 2
|
1天前
使用字节输入流报错 java.io.FileNotFoundException: srcdruid.properties (系统找不到指定的文件。)
使用字节输入流报错 java.io.FileNotFoundException: srcdruid.properties (系统找不到指定的文件。)
6 0
|
21天前
|
Java 应用服务中间件
已解决:An error occurred at line: 1 in the generated java file The type java.io.ObjectInputStream canno
已解决:An error occurred at line: 1 in the generated java file The type java.io.ObjectInputStream canno
17 0
|
21天前
|
Java
文件操作与IO(3) 文件内容的读写——数据流
文件操作与IO(3) 文件内容的读写——数据流
15 0
|
21天前
|
Java Windows
文件操作和IO(2):Java中操作文件
文件操作和IO(2):Java中操作文件
11 0
|
13小时前
|
存储 Java 机器人
Java中的IO操作技巧与性能优化
Java中的IO操作技巧与性能优化
|
1天前
|
存储 Java 机器人
Java中的IO操作技巧与性能优化
Java中的IO操作技巧与性能优化