gpt4 book ai didi

python - 在 Open3D 中不打开 Visualizer 捕获深度图像?

转载 作者:行者123 更新时间:2023-12-05 04:43:11 26 4
gpt4 key购买 nike

我希望批量处理 50,000 多个 3D 模型。我需要从不同角度捕捉深度图。使用 Open3D,如何在不启动可视化工具的情况下捕获此信息?希望加快这个过程?

最佳答案

你可以查看 Open3D OffScreen

它会在没有窗口的情况下渲染深度图或图像,换句话说,它可以在后台运行批处理。

这是例子。

import copy
from cv2 import cv2
import numpy as np
import open3d as o3d
import matplotlib.pyplot as plt

img_width, img_height = (1920, 1080)
pcd = o3d.io.read_triangle_mesh('bunny.ply')

mat = o3d.visualization.rendering.Material()
mat.shader = 'defaultUnlit'

renderer_pc = o3d.visualization.rendering.OffscreenRenderer(img_width, img_height)
renderer_pc.scene.set_background(np.array([0, 0, 0, 0]))
renderer_pc.scene.add_geometry("pcd", pcd, mat)

# Optionally set the camera field of view (to zoom in a bit)
vertical_field_of_view = 15.0 # between 5 and 90 degrees
aspect_ratio = img_width / img_height # azimuth over elevation
near_plane = 0.1
far_plane = 50.0
fov_type = o3d.visualization.rendering.Camera.FovType.Vertical
renderer_pc.scene.camera.set_projection(vertical_field_of_view, aspect_ratio, near_plane, far_plane, fov_type)

# Look at the origin from the front (along the -Z direction, into the screen), with Y as Up.
center = [0, 0, 0] # look_at target
eye = [0, 0, 2] # camera position
up = [0, 1, 0] # camera orientation
renderer_pc.scene.camera.look_at(center, eye, up)

depth_image = np.asarray(renderer_pc.render_to_depth_image())
np.save('depth', depth_image)

normalized_image = (depth_image - depth_image.min()) / (depth_image.max() - depth_image.min())
plt.imshow(normalized_image)
plt.savefig('depth.png')

enter image description here

关于python - 在 Open3D 中不打开 Visualizer 捕获深度图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69696354/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com