capture_screen_image
函数用于将当前Open3D可视化窗口的内容以图像的形式保存下来。
def capture_screen_image(filename=None, do_render=True):
"""
Captures the current screen content (including overlays of 2D and 3D
images), and saves it as an image file.
:param filename: A string of image file name. If None or not specified,
the image content will be returned.
:param do_render: if True, render the screen content before capturing
:type filename: str or None
:type do_render: bool
:return: An image content as a numpy array (if filename is None or not specified),
otherwise return None
"""
filename
:图片文件名,如果为None
或未指定,则该函数将返回图像内容。do_render
:如果为True
,在捕获前渲染屏幕内容。如果filename
为None
或未指定,则该函数将返回图像内容作为NumPy数组,否则返回None
。
import open3d as o3d
# 创建点云
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector([[0, 0, 0], [0, 1, 0], [1, 0, 0]])
# 可视化点云
vis = o3d.visualization.VisualizerWithEditing()
vis.create_window()
vis.add_geometry(pcd)
vis.run()
# 保存屏幕截图
vis.capture_screen_image("screenshot.png")
上述示例将创建一个点云,并在可视化窗口中呈现。然后,capture_screen_image
函数将保存屏幕截图,并将其保存为screenshot.png
文件。如果未指定filename
参数,则函数将返回NumPy数组形式的图像内容。