简体   繁体   English

无需在 Open3D 中打开 Visualizer 即可捕获深度图像?

[英]Capture Depth Image without opening Visualizer in Open3D?

I'm looking to batch process 50,000+ 3D models.我希望批量处理 50,000 多个 3D 模型。 I need to capture depth maps from different angles.我需要从不同角度捕捉深度图。 Using Open3D, How can I capture this information without launching the visualizer?使用 Open3D,如何在不启动可视化工具的情况下捕获此信息? In hopes of speeding up the process?希望加快进程?

You could check Open3D OffScreen你可以检查Open3D OffScreen

Here are the example.这是示例。

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')

在此处输入图片说明

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

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