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

问题描述

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

o3d.geometry.RGBDImage.create_from_color_and_depth(img,depth)

但是我得到了错误:

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

如何解决此问题?如果需要图像类型,那么如何将numpy数组转换为图像类型?

即使我将numpy数组传递给o3d.geometry.Image构造函数,例如:

o3d.geometry.RGBDImage.create_from_color_and_depth(o3d.geometry.Image(img),o3d.geometry.Image(depth))

我得到了错误:

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

如何解决此问题并从rgb numpy数组和depth numpy数组创建RGBD图像?

解决方法

如果您分享一个可复制的示例,那会很好,但是我认为从np.array创建Image并不像基于signature调用ctor那样简单。这不一定是uint8的数组,对吧?

基于this article,您必须按照以下步骤创建它:

depth_as_img = o3d.geometry.Image((depth).astype(np.uint8))

,然后进一步传递到create_from_color_and_depth。因此,您必须明确指定它是uint8s的数组。

,

您应该在此函数中检查convert_rgb_to_intensity参数。默认情况下,它将使用灰度图像。这样,您的彩色图像应该只有一个通道。如果要使用RGB,请将该参数设置为false,然后查看是否可以解决。

此外,对于从numpy到open3d图像的其他注释:https://github.com/intel-isl/Open3D/issues/957

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...