API
open3d.io.read_point_cloud(filename, format='auto', remove_nan_points=False, remove_infinite_points=False, print_progress=False)
open3d.io.write_point_cloud(filename, pointcloud, write_ascii=False, compressed=False, print_progress=False)
其中,format 包括:
xyz: 三维坐标[x, y, z]
xyzn: 三维坐标 + 归一化坐标 [x, y, z, nx, ny, nz]
xyzrgb: 三维坐标+ 颜色归一化值s [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] ,x, y, z, i 为double 类型,r, g, b 为uint8;
ply;
pcd;
import open3d as o3d
pcd = o3d.io.read_point_cloud("bunny.pcd")
o3d.visualization.draw(pcd)
o3d.io.write_point_cloud("copy_bunny.pcd", pcd)
open3d.io.read_triangle_mesh(filename, enable_post_processing=False, print_progress=False)
open3d.io.write_triangle_mesh(filename, mesh, write_ascii=False, compressed=False, write_vertex_normals=True, write_vertex_colors=True, write_triangle_uvs=True, print_progress=False)
其中,可读取format 包括ply、stl、obj、off、gltf/glb;
import open3d as o3d
plymesh = o3d.io.read_triangle_mesh("bunny10k.ply")
o3d.visualization.draw(plymesh)
o3d.io.write_triangle_mesh("copy_bunny10k.ply", plymesh)
#读图片数据
open3d.io.read_image(filename)
#基于rgb图和depth图,生成rgbd图像
o3d.geometry.RGBDImage.create_from_color_and_depth(color, depth, depth_scale=1000.0, depth_trunc=3.0, convert_rgb_to_intensity=True)
import open3d as o3d
import matplotlib.pyplot as plt
print("Read Redwood dataset")
# 读取rgb图像
color_raw = o3d.io.read_image("00000.jpg")
# 读取深度图像
depth_raw = o3d.io.read_image("00000.png")
# RGBD图像
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
color_raw, depth_raw)
print(rgbd_image)
plt.subplot(1, 2, 1)
plt.title('Redwood grayscale image')
plt.imshow(rgbd_image.color)
plt.subplot(1, 2, 2)
plt.title('Redwood depth image')
plt.imshow(rgbd_image.depth)
plt.show()
# 根据相机内参从深度图计算点云
pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
rgbd_image,
o3d.camera.PinholeCameraIntrinsic(
o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
o3d.visualization.draw_geometries([pcd])