繁体   English   中英

从 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 的助手function。

方法 2 使用 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'])

使用 open3d,如果我不使用 opencv 读取它,我可以创建 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])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM