目錄
1. read_image, write_image
2. read_point_cloud, write_point_cloud
3. 深度相機(jī)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
讀寫點(diǎn)云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. 深度相機(jī)IO操作
讀取深度相機(jī)
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() # 深度相機(jī),比如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轉(zhuǎn)
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網(wǎng)格數(shù)據(jù),ply等文件文章來源:http://www.zghlxwxcb.cn/news/detail-438313.html
triangle_mesh_io.py文章來源地址http://www.zghlxwxcb.cn/news/detail-438313.html
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)
到了這里,關(guān)于open3d io操作的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!