File IO¶
This tutorial shows how basic geometries are read and written by Open3D.
Point cloud¶
This code below reads and writes a point cloud.
[2]:
print("Testing IO for point cloud ...")
pcd = o3d.io.read_point_cloud("../../TestData/fragment.pcd")
print(pcd)
o3d.io.write_point_cloud("copy_of_fragment.pcd", pcd)
Testing IO for point cloud ...
geometry::PointCloud with 113662 points.
[2]:
True
print()
can be used for displaying a summary of pcd.
By default, Open3D tries to infer the file type by the filename extension. Below is a list of supported point cloud file types.
Format |
Description |
---|---|
|
Each line contains |
|
Each line contains |
|
Each line contains |
|
The first line is an integer representing the number of points. Each subsequent line contains |
|
See Polygon File Format, the ply file can contain both point cloud and mesh data |
|
See Point Cloud Data |
It’s also possible to specify the file type explicitly. In this case, the file extension will be ignored.
[3]:
pcd = o3d.io.read_point_cloud("../../TestData/my_points.txt", format='xyz')
Mesh¶
This code below reads and writes a mesh.
[4]:
print("Testing IO for meshes ...")
mesh = o3d.io.read_triangle_mesh("../../TestData/knot.ply")
print(mesh)
o3d.io.write_triangle_mesh("copy_of_knot.ply", mesh)
Testing IO for meshes ...
geometry::TriangleMesh with 1440 points and 2880 triangles.
[4]:
True
Compared to the data structure of point cloud, mesh has triangles that define the 3D surface.
By default, Open3D tries to infer the file type by the filename extension. Below is a list of supported triangle mesh file types.
Format |
Description |
---|---|
|
See Polygon File Format, the ply file can contain both point cloud and mesh data |
|
|
|
See Object Files |
|
|
|
Image¶
The code below reads and writes an image.
[5]:
print("Testing IO for images ...")
img = o3d.io.read_image("../../TestData/lena_color.jpg")
print(img)
o3d.io.write_image("copy_of_lena_color.jpg", img)
Testing IO for images ...
Image of size 512x512, with 3 channels.
Use numpy.asarray to access buffer data.
[5]:
True
The size of the image is readily displayed using print(img)
.