open3d学习系列之1读取深度图和彩色图生成点云数据

open3d学习系列之1读取深度图和彩色图生成点云数据

import pyrealsense2 as rs
import numpy as np
import cv2
import matplotlib.pyplot as plt
import open3d as o3d

# load image and depth from .png and .npz file
img_f = 'abc.png'
color_image = cv2.imread(img_f)
cv2.imshow('img', color_image)
cv2.waitKey(1)
depth_image = np.load(img_f.replace('.png', '.npz'))['data']

o3d_color = o3d.geometry.Image(color_image)
o3d_depth = o3d.geometry.Image(depth_image)
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(o3d_color, o3d_depth,
                                                                depth_scale=1000.0,
                                                                depth_trunc=1000.0)
# 转换为open3d中的相机参数
pinhole_camera_intrinsic = o3d.camera.PinholeCameraIntrinsic(
    intrinsics.width, intrinsics.height,
    intrinsics.fx, intrinsics.fy,
    intrinsics.ppx, intrinsics.ppy
)

# use open3d save to ply file
tmp = o3d.geometry.PointCloud.create_from_rgbd_image(
    rgbd_image,
    pinhole_camera_intrinsic
)
o3d.io.write_point_cloud("1_open3d.ply", o3d_result)

你可能感兴趣的:(pcl,Python,点云,opencv,计算机视觉,open3d)