从 realsense API 或 Open3D 库中可视化点云

visualizing the pointcloud from realsense API or Open3D library

我有一个来自英特尔实感相机的深度帧,我想将它转换为点云并可视化点云。到目前为止,至于只给定深度框架和相机内在函数来创建点云,我发现了以下两个函数,但是我似乎找不到一种方法来可视化其中一个函数或将它们存储为 .ply 文件。

我应该如何可视化以这种方式制作的点云?

方法一:

pointcloud = convert_depth_frame_to_pointcloud(original_depth_frame, color_intrinsics)

其中 convert_depth_frame_to_pointcloud 是来自 RealSense 的 helper function

方法二使用Open3D库:

pcd = o3d.geometry.PointCloud.create_from_depth_image(original_depth_frame, color_intrinsics)
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
print(np.asarray(pcd.points)[1, :])  
o3d.visualization.draw_geometries([pcd])

另外,当使用 o3d 时,我得到这个错误:

create_from_depth_image(): incompatible function arguments. The following argument types are supported:
    1. (depth: open3d::geometry::Image, intrinsic: open3d.cuda.pybind.camera.PinholeCameraIntrinsic, extrinsic: numpy.ndarray[float64[4, 4]] = array([[1., 0., 0., 0.],
       [0., 1., 0., 0.],
       [0., 0., 1., 0.],
       [0., 0., 0., 1.]]), depth_scale: float = 1000.0, depth_trunc: float = 1000.0, stride: int = 1, project_valid_depth_only: bool = True) -> open3d.cuda.pybind.geometry.PointCloud

这里的original_depth_frame读作:

frame = cv2.imread(os.path.join(args.depth_input_dir, imgs_dir[frame_idx]), cv2.IMREAD_ANYDEPTH)

其中一张深度图是这样的:

000248.png PNG 1280x720 1280x720+0+0 16-bit Grayscale Gray 567278B 0.000u 0:00.000

其中 color_intrinsics 是:

def set_intrinsics(intrinsics_dict):
    intrinsics = rs.intrinsics()
    intrinsics.width = intrinsics_dict['width']
    intrinsics.height = intrinsics_dict['height']
    intrinsics.ppx = intrinsics_dict['ppx']
    intrinsics.ppy = intrinsics_dict['ppy']
    intrinsics.fx = intrinsics_dict['fx']
    intrinsics.fy = intrinsics_dict['fy']
    intrinsics.model = intrinsics_dict['model']
    intrinsics.coeffs = intrinsics_dict['coeffs']
    return intrinsics
color_intrinsics = set_intrinsics(camera['color_intrinsics'])

如果我不使用 opencv 读取它,我可以使用 open3d 创建 PNG 格式的深度图像的点云(但是我需要在我的代码中这样做)。

import open3d as o3d
import matplotlib.pyplot as plt
import numpy as np

raw_depth = o3d.io.read_image('depth_images/000248.png')
pcd = o3d.geometry.PointCloud.create_from_depth_image(raw_depth, 
o3d.camera.PinholeCameraIntrinsic(
                                  o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault)
                                , np.identity(4), depth_scale=1000.0, depth_trunc=1000.0)
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
print(np.asarray(pcd.points)[1,:])
o3d.visualization.draw_geometries([pcd])

^^ 上面的代码生成了一个 3D 点云。

您需要阅读您的图像,如下所示:

import open3d as o3d
import matplotlib.pyplot as plt
import numpy as np

raw_depth = o3d.io.read_image('depth_images/000248.png')
pcd = o3d.geometry.PointCloud.create_from_depth_image(raw_depth, 
o3d.camera.PinholeCameraIntrinsic(
                                  o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault)
                                , np.identity(4), depth_scale=1000.0, depth_trunc=1000.0)
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
print(np.asarray(pcd.points)[1,:])
o3d.visualization.draw_geometries([pcd])