简体   繁体   English

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

[英]how to create a rgbd Image from numpy rgb array and depth array?

I have a numpy array which is the color image "img" of shape (height, width, 3), and also a depth numpy array of shape (height, width).我有一个 numpy 数组,它是形状(高度,宽度,3)的彩色图像“img”,也是形状(高度,宽度)的深度 numpy 数组。 And I want to create an RGBD image and display it, for which I'm doing the following:我想创建一个 RGBD 图像并显示它,为此我正在执行以下操作:

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

But I'm getting the error:但我收到错误:

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

How to fix this?如何解决这个问题? If it requires an Image type, then how to convert the numpy array to an Image type?如果它需要 Image 类型,那么如何将 numpy 数组转换为 Image 类型?

Even when I pass in the numpy arrays into the o3d.geometry.Image constructors like so:即使我将 numpy 数组传入 o3d.geometry.Image 构造函数,如下所示:

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

I get the error:我收到错误:

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

How to fix this and create the RGBD image from the rgb numpy array and the depth numpy array?如何解决此问题并从 rgb numpy 数组和深度 numpy 数组创建 RGBD 图像?

Would be great if you shared reproducible example, but I think that creating Image from np.array isn't as simple as calling the ctor, basing on signature .如果您共享可重现的示例,那就太好了,但我认为从 np.array 创建Image并不像基于signature调用 ctor 那样简单。 This is not necessarily an array of uint8, right?这不一定是 uint8 数组,对吗?

Basing on this article , you have to create it as follows:根据本文,您必须按如下方式创建它:

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

and pass further to create_from_color_and_depth .并进一步传递给create_from_color_and_depth So, you have to explicitly specify that it's an array of uint8s.因此,您必须明确指定它是一个 uint8 数组。

You should check the convert_rgb_to_intensity parameter in this function.您应该检查此函数中的convert_rgb_to_intensity参数。 By default, it will use the greyscale image.默认情况下,它将使用灰度图像。 In this way, your color image should have only one channel.这样,您的彩色图像应该只有一个通道。 If you want RGB, set that parameter to false and see if it solves.如果你想要 RGB,将该参数设置为 false,看看它是否能解决。

In addition, extra comments for from numpy to open3d image: https://github.com/intel-isl/Open3D/issues/957此外,从 numpy 到 open3d 图像的额外注释: https : //github.com/intel-isl/Open3D/issues/957

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

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