我想从网格文件和相机参数渲染深度,为此,我try 了从open3d中使用这个mesh file渲染RaycastingScene,如下所示:

#!/usr/bin/env python3

import numpy as np
import open3d as o3d
import matplotlib.pyplot as plt


def render_depth(
    intrins:o3d.core.Tensor,
    width:int,
    height:int,
    extrins:o3d.core.Tensor,
    tmesh:o3d.t.geometry.TriangleMesh
)->np.ndarray:
    """
    Render depth from mesh file

    Parameters
    ----------
    intrins : o3d.core.Tensor
        Camera Intrinsics matrix K: 3x3
    width : int
        image width
    height : int
        image height
    extrins : o3d.core.Tensor
        camera extrinsics matrix 4x4
    tmesh : o3d.t.geometry.TriangleMesh
        TriangleMesh

    Returns
    -------
    np.ndarray
        Rendred depth image
    """
    scene = o3d.t.geometry.RaycastingScene()
    scene.add_triangles(tmesh)
    
    rays = scene.create_rays_pinhole(
        intrinsic_matrix=intrins,
        extrinsic_matrix=extrins,
        width_px=width, height_px=height
    )
    
    ans = scene.cast_rays(rays)
    t_hit = ans["t_hit"].numpy() / 1000.0

    return t_hit


if __name__=="__main__":
    import os
    mesh_path = f"{os.getenv('HOME')}/bbq_sauce.ply"
    mesh = o3d.t.io.read_triangle_mesh(mesh_path)
    mesh.compute_vertex_normals()
    
    # camera_info[k].reshape(3, 3)
    intrins_ = np.array([
            [606.9275512695312, 0.0, 321.9704895019531],
            [0.0, 606.3505859375, 243.5377197265625],
            [0.0, 0.0, 1.0]
            ])
    width_  = 640 # camera_info.width
    height_ = 480 # camera_info.height
    # root2cam 4x4
    extrens_ = np.eye(4)
    #
    intrins_t = o3d.core.Tensor(intrins_)
    extrins_t = o3d.core.Tensor(extrens_)
    
    rendered_depth = render_depth(
        intrins=intrins_t, 
        width=width_, 
        height=height_, 
        extrins = extrins_t, 
        tmesh=mesh
    )
    
    plt.imshow(rendered_depth)
    plt.show()

但我得到的深度图像似乎不正确!

你能告诉我如何解决这个问题吗?谢谢.

enter image description here

推荐答案

光线投射场景工作正常.然而,您的外部矩阵正在将摄像机设置在网格内,因此您可以看到网格从内部看起来如何.

我在网状实验室中粗略测量了网格bbq_sauce,宽度约为53个单位.您可以使用以下方法之一将相机从网格移开:

extrens_[2, 3] = 200

或者不移动对象,而只是移动相机姿势.

rays = o3d.t.geometry.RaycastingScene.create_rays_pinhole(
        fov_deg=90,  # Not computed from intrinsic parameters.
        center=[0, 0, 0],  # Look towards
        eye=[100, 100, 0],  # Look from
        up=[0, 1, 0],  # This helps in orienting the camera so object is not inverted.
        width_px=640,
        height_px=480,
    )

Image of a barbeque sauce 3d model rendered using RaycastingScene class from Open3D

Python相关问答推荐

在IIS中运行的FastAPI-获取权限错误:[Win错误10013]试图以其访问权限禁止的方式访问插槽

Altair -箱形图边界设置为黑色,中线设置为红色

这家einsum运营在做什么?E = NP.einsum(aj,kl-il,A,B)

基本链合同的地址是如何计算的?

如何使用stride_tricks.as_strided逆转NumPy数组

跟踪我已从数组中 Select 的样本的最有效方法

仅从风格中获取 colored颜色 循环

我必须将Sigmoid函数与r2值的两种类型的数据集(每种6个数据集)进行匹配,然后绘制匹配函数的求导.我会犯错

如何才能知道Python中2列表中的巧合.顺序很重要,但当1个失败时,其余的不应该失败或是0巧合

使用mySQL的SQlalchemy过滤重叠时间段

如果条件为真,则Groupby.mean()

比较两个数据帧并并排附加结果(获取性能警告)

当多个值具有相同模式时返回空

当使用keras.utils.Image_dataset_from_directory仅加载测试数据集时,结果不同

将数据框架与导入的Excel文件一起使用

在Mac上安装ipython

无法定位元素错误404

基于索引值的Pandas DataFrame条件填充

在极性中创建条件累积和

Flask Jinja2如果语句总是计算为false&