简体   繁体   English

在 pyrender/open3d 中的点云顶点上显示文本

[英]Display text on point cloud vertex in pyrender/open3d

I am using SMPL demo code to display the SMPL-X mesh of a person.我正在使用SMPL 演示代码来显示一个人的 SMPL-X 网格。 Instead of taking the default body joints, I need to select vertices corresponding to some other positions on the mesh, and for that I need to figure out the respective indices of those joints.我不需要采用默认的身体关节,而是需要 select 个顶点对应于网格上的其他一些位置,为此我需要找出这些关节的各自索引。 Easiest way of doing that that I could think of is simply displaying some text over each vertex with its numeric id, will look messy but zooming in should be a fast way of getting what I need.我能想到的最简单的方法是简单地在每个顶点上显示一些带有数字 ID 的文本,看起来会很乱,但放大应该是获得我需要的东西的快速方法。

The demo code I linked above is using 3 separate libraries to display the mesh: pyrender, matplotlib and open3d.我上面链接的演示代码使用 3 个独立的库来显示网格:pyrender、matplotlib 和 open3d。 Matplotlib is super slow and becomes unusable when displaying all the vertices in the mesh, but it's also the only one where it's trivial to display the vertex indices since it's as easy as: Matplotlib 非常慢并且在显示网格中的所有顶点时变得不可用,但它也是唯一一个显示顶点索引是微不足道的,因为它非常简单:

    for idx, j in enumerate(joints):
        ax.text(j[0], j[1], j[2], str(idx), None)

And produces this并产生这个在此处输入图像描述

which is exactly what I need.这正是我所需要的。 Looks messy but zooming in makes it much more readable, except it takes like 5 minutes to get to the right position on the hands because of how terrible matplotlib 3D visualization is.看起来很乱,但放大后可读性更强,除了需要 5 分钟才能找到正确的 position,因为 matplotlib 3D 的可视化效果非常糟糕。

I have spent 1 hour trying to figure out how to achieve the same using either pyrender or open3d, but I'm not familiar with neither of the two and from what I could find, there isn't a straightforward way of putting this kind of text on some positions in a point cloud.我花了 1 小时试图弄清楚如何使用 pyrender 或 open3d 实现相同的效果,但我对这两者都不熟悉,而且从我能找到的情况来看,没有一种直接的方法来放置这种点云中某些位置的文本。 Does anyone have an idea on how to do this with either one of these libs?有没有人知道如何使用这些库中的任何一个来做到这一点? Any help will be much appreciated!任何帮助都感激不尽!

I'm currently working with Open3D so I might have some insights.我目前正在使用 Open3D,所以我可能会有一些见解。

I suggest reading the Open3D docs about io .我建议阅读有关 io 的 Open3D 文档

You can easily load a mesh with open3d.io.read_triangle_mesh('path/to/mesh') and add a Label with sceneWidget.add_3d_label([x, y, z], 'label text') .您可以使用open3d.io.read_triangle_mesh('path/to/mesh')轻松加载网格,并使用sceneWidget.add_3d_label([x, y, z], 'label text')添加 Label。

Below is an small example.下面是一个小例子。 If you need mouse-events it's quite a bit more complicated but for simply displaying it this might work.如果您需要鼠标事件,则要复杂得多,但是对于简单地显示它来说,这可能会起作用。 Note that I have only tested it with a point cloud.请注意,我只使用点云对其进行了测试。

import open3d as o3d
import open3d.visualization.gui as gui
import open3d.visualization.rendering as rendering

if __name__ == "__main__":
    gui.Application.instance.initialize()

    window = gui.Application.instance.create_window("Mesh-Viewer", 1024, 750)

    scene = gui.SceneWidget()
    scene.scene = rendering.Open3DScene(window.renderer)

    window.add_child(scene)

    # mesh = o3d.io.read_triangle_mesh('path/to/data', print_progress=True)
    mesh = o3d.io.read_point_cloud('path/to/data', print_progress=True)

    scene.scene.add_geometry("mesh_name", mesh, rendering.MaterialRecord())

    bounds = mesh.get_axis_aligned_bounding_box()
    scene.setup_camera(60, bounds, bounds.get_center())

    labels = [[0, 0, 0]]
    for coordinate in labels:
        scene.add_3d_label(coordinate, "label at origin")

    gui.Application.instance.run()  # Run until user closes window

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

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