python点云处理模块_Open3D 点云处理方法示例 - Python版

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值