目录
1. read_image, write_image
2. read_point_cloud, write_point_cloud
3. 深度相机IO操作
4. Mesh文件读取
1. read_image, write_image
读取jpg. png. bmp等文件
image_io.py
import open3d as o3d
if __name__ == "__main__":
img_data = o3d.data.JuneauImage()
print(f"Reading image from file: Juneau.jpg stored at {img_data.path}")
# 1. read
img = o3d.io.read_image(img_data.path) # JuneauImage.jpg
print(img) # open3d.geometry.Image. Image of size 800x489, with 3 channels.
print("Saving image to file: copy_of_Juneau.jpg")
# 2. write
o3d.io.write_image("copy_of_Juneau.jpg", img) # open3d.geometry.Image
2. read_point_cloud, write_point_cloud
读写点云pcd, ply等文件
point_cloud_io.py
import open3d as o3d
if __name__ == "__main__":
pcd_data = o3d.data.PCDPointCloud()
print(
f"Reading pointcloud from file: fragment.pcd stored at {pcd_data.path}")
# 1. read PointCloud.pcd
pcd = o3d.io.read_point_cloud(pcd_data.path)
print(pcd)
print("Saving pointcloud to file: copy_of_fragment.pcd")
# 2. write PointCloud
o3d.io.write_point_cloud("copy_of_fragment.pcd", pcd)
3. 深度相机IO操作
读取深度相机
realsense_io.py
"""Demonstrate RealSense camera discovery and frame capture"""
import open3d as o3d
if __name__ == "__main__":
o3d.t.io.RealSenseSensor.list_devices()
rscam = o3d.t.io.RealSenseSensor() # 深度相机,比如D435i
rscam.start_capture()
print(rscam.get_metadata())
for fid in range(5):
rgbd_frame = rscam.capture_frame()
o3d.io.write_image(f"color{fid:05d}.jpg", rgbd_frame.color.to_legacy()) # 彩色图像. tensor转
o3d.io.write_image(f"depth{fid:05d}.png", rgbd_frame.depth.to_legacy()) # 深度图像
print("Frame: {}, time: {}s".format(fid, rscam.get_timestamp() * 1e-6))
rscam.stop_capture()
4. Mesh文件读取
读取mesh网格数据,ply等文件
triangle_mesh_io.py
import open3d as o3d
if __name__ == "__main__":
knot_data = o3d.data.KnotMesh()
print(f"Reading mesh from file: knot.ply stored at {knot_data.path}")
mesh = o3d.io.read_triangle_mesh(knot_data.path) # TriangleMesh
print(mesh)
print("Saving mesh to file: copy_of_knot.ply")
o3d.io.write_triangle_mesh("copy_of_knot.ply", mesh)