1. PCD 格式读取
import open3d as o3d
o3d.io.read_point_cloud("XXXX.pcd")
2. PLY格式读取
import open3d as o3d
o3d.io.read_point_cloud("XXXX.ply")
3. 读取RGB和Depth图像转换为点云(自定义内参)
import open3d as o3d
import numpy as np
#加载图片
color_raw = o3d.io.read_image("rgb_name.png")
depth_raw = o3d.io.read_image("depth_name.png")
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(color_raw, depth_raw)
#内参赋值
width,height,fx, fy, cx, cy = 640,480,450.2, 450.4, 316.3, 192.0
intrinsic = o3d.camera.PinholeCameraIntrinsic(width, height, fx, fy, cx, cy)
pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
rgbd_image,intrinsic)
# Flip it, otherwise the pointcloud will be upside down
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
# 显示
o3d.visualization.draw_geometries([pcd])
4. RGBD图-ICP示例
import open3d as o3d
import numpy as np
width,height,fx, fy, cx, cy = 640,480,450.2, 450.4, 316.3, 192.0
intrinsic = o3d.camera.PinholeCameraIntrinsic(width, height, fx, fy, cx, cy)
color_raw_source = o3d.io.read_image("rgb_source.png")
depth_raw_source = o3d.io.read_image("depth_source.png")
rgbd_image_source = o3d.geometry.RGBDImage.create_from_color_and_depth(color_raw_source, depth_raw_source)
source = o3d.geometry.PointCloud.create_from_rgbd_image(
rgbd_image_source,intrinsic)
color_raw_target = o3d.io.read_image("rgb_target.png")
depth_raw_target = o3d.io.read_image("depth_target.png")
rgbd_image_target = o3d.geometry.RGBDImage.create_from_color_and_depth(color_raw_target, depth_raw_target)
target = o3d.geometry.PointCloud.create_from_rgbd_image(
rgbd_image_target,intrinsic)
threshold = 1.0 #移动范围的阀值
trans_init = np.asarray([[1,0,0,0], # 4x4 identity matrix,这是一个转换矩阵,
[0,1,0,0], # 象征着没有任何位移,没有任何旋转,
[0,0,1,0], # 初始化为单位证
[0,0,0,1]])
reg_p2p = o3d.registration.registration_icp(
source, target, threshold, trans_init,
o3d.registration.TransformationEstimationPointToPoint(),
o3d.registration.ICPConvergenceCriteria(relative_fitness=1.000000e-06, relative_rmse=1.000000e-06,max_iteration=50))
source.transform(reg_p2p.transformation) #将源点云做转换
vis = o3d.visualization.Visualizer()
vis.create_window()
#将两个点云放入visualizer
vis.add_geometry(source)
vis.add_geometry(target)
#让visualizer渲染点云
vis.poll_events()
vis.update_renderer()
vis.run()