admin管理员组

文章数量:1534214

文章目录

    • ImageWidget
    • 图像控件

Open3d快速上手💎 点云对象详解

ImageWidget

作为三维点云工具,Open3D连三维的形状都能画出来,那二维的图像就更不在话下了。ImageWidgetgui中显示图像的控件,和大多数控件不同的是,图像控件提供了多种构造函数

  1. 无参数,将生成一个没有图像的占位区域
  2. 输入路径,将打开该路径所对应的图像
  3. 输入Image类型的数据
  4. 输入t.geometry中的Image类型数据

图像控件

现以第二种为例,创建一个图像控件

import open3d as o3d
import open3d.visualization.gui as gui
import open3d.visualization.rendering as rendering
app = gui.Application.instance

app.initialize()
win = app.create_window("Image")
imgFrame = gui.ImageWidget("test.jpg")
win.add_child(imgFrame)
app.run()

这个效果没什么好看的,就不展示了。

Imageopen3d.geometry中的一种数据类型,其默认的初始化方式是通过矩阵,下面用随机数生成一个矩阵,并装载到图像中

import numpy as np
img_data = (np.random.rand(300, 600)*255).astype(np.uint8)
img = o3d.geometry.Image(img_data)
imgFrame = gui.ImageWidget(img)

效果如下


ImageWidget中提供了update_image的方法,可以更新显示的图像内容,其输入参数同样为Image类型数据。其官网说明如下

Mostly a convenience function for ui_image.update_image(). If ‘image’ is the same size as the current image, will update the texture with the contents of ‘image’. This is the fastest path for setting an image, and is recommended if you are displaying video. If ‘image’ is a different size, it will allocate a new texture, which is essentially the same as creating a new UIImage and calling SetUIImage(). This is the slow path, and may eventually exhaust internal texture resources.

此外,也可以将图像数据点云化,然后再通过三维显示控件显示出来。回顾在点云类中学到的内容,通过一个深度图像和一个rgb图像,就可以创建点云。

raw = o3d.io.read_image("test.jpg")
depth = o3d.geometry.Image(np.ones([610, 1024],dtype=np.uint8))
rgbd = o3d.geometry.RGBDImage.create_from_color_and_depth(raw, depth, convert_rgb_to_intensity=False)
inter = o3d.camera.PinholeCameraIntrinsic()
inter.set_intrinsics(1024, 610, 500, 500, 512, 305)
pcd = o3d.geometry.PointCloud().create_from_rgbd_image(rgbd, inter)
o3d.visualization.draw_geometries([pcd])

其效果如图所示

下一篇即讲解open3d中最强大的UI控件SceneWidget

本文标签: 图像open3d