如何从 numpy rgb 数组和深度数组创建 rgbd 图像?

zen*_*vil 10 python arrays numpy open3d

我有一个 numpy 数组,它是形状(高度,宽度,3)的彩色图像“img”,也是形状(高度,宽度)的深度 numpy 数组。我想创建一个 RGBD 图像并显示它,为此我正在执行以下操作:

o3d.geometry.RGBDImage.create_from_color_and_depth(img, depth)
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

TypeError: create_from_color_and_depth(): incompatible function arguments. The following argument types are supported:
    1. (color: open3d.open3d_pybind.geometry.Image, depth: open3d.open3d_pybind.geometry.Image, depth_scale: float = 1000.0, depth_trunc: float = 3.0, convert_rgb_to_intensity: bool = True) -> open3d.open3d_pybind.geometry.RGBDImage

Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?如果需要Image类型,那么如何将numpy数组转换为Image类型?

即使我将 numpy 数组传递到 o3d.geometry.Image 构造函数中,如下所示:

o3d.geometry.RGBDImage.create_from_color_and_depth(o3d.geometry.Image(img), o3d.geometry.Image(depth))
Run Code Online (Sandbox Code Playgroud)

我收到错误:

TypeError: create_from_color_and_depth(): incompatible function arguments. The following argument types are supported:
    1. (color: open3d.open3d_pybind.geometry.Image, depth: open3d.open3d_pybind.geometry.Image, depth_scale: float = 1000.0, depth_trunc: float = 3.0, convert_rgb_to_intensity: bool = True) -> open3d.open3d_pybind.geometry.RGBDImage

Run Code Online (Sandbox Code Playgroud)

如何解决这个问题并从 rgb numpy 数组和深度 numpy 数组创建 RGBD 图像?

Mar*_*ski 3

如果您分享可重现的示例,那就太好了,但我认为Image从 np.array 创建并不像基于签名调用 ctor 那么简单。这不一定是 uint8 数组,对吧?

基于这篇文章,您必须按如下方式创建它:

depth_as_img = o3d.geometry.Image((depth).astype(np.uint8))
Run Code Online (Sandbox Code Playgroud)

并进一步传递到create_from_color_and_depth. 因此,您必须明确指定它是 uint8 数组。

  • 就我而言,深度图像的类型为“np.float32”,也可以正常工作。但是,您还必须确保它也是一个 c 类型数组。这是默认的,所以你不需要太担心它,但如果它不是c类型,你可以使用`o3d.geometry.Image(np.ascontigouslyarray(np_array).astype(np.float32)) ` 以避免错误。 (3认同)