点云Cloud<XYZ>和彩色点云Cloud(XYZ-RGB)的格式均为.ply
示例:以将深度图转换为点云为例(python36+Mech-Vision1.7.1)
step1:配置open3d环境
Mech-Vision路径下的python环境中默认没有安装open3d,因此在使用open3d库之前需要安装open3d模块
(安装python环境时会自动安装open3d库,可直接将其复制至Mech-Vision根目录下的Python环境下)
step2:编写.py脚本程序
depth_to_pointCloud.py
import open3d as o3d
def output(color_img,depth_img):
# load color image and depth iamge
o3d_color=o3d.geometry.Image(color_img)
o3d_depth=o3d.geometry.Image(depth_img)
rgbd_image=o3d.geometry.RGBDImage.create_from_color_and_depth(
o3d_color,
o3d_depth,
depth_scale=1000.0,
depth_trunc=1000.0
)
# 转换为open3d中的相机参数(分辨率、焦距、光学中心)
fy, cx, cy = 1280,1024,450.2, 450.4, 316.3, 192.0
pinhole_camera_intrinsic = o3d.camera.PinholeCameraIntrinsic(
height,
fy,
cy
)
# use open3d save to ply file
o3d_result=o3d.geometry.PointCloud.create_from_rgbd_image(
rgbd_image,
pinhole_camera_intrinsic
)
path='C:\\Users\\mechmind\\Desktop\\PointCloud.ply'
o3d.io.write_point_cloud(path,o3d_result)
step3:设置输入和输出参数
step4:运行
在指定路径下生成.py程序