简体   繁体   English

Open3d 中的非阻塞可视化

[英]Non BLocking Visualization in Open3d

I have 2 different pointclouds stored in 2 different numpy arrays and I can visualize them combined in open3d.我有 2 个不同的点云存储在 2 个不同的 numpy 数组中,我可以将它们组合在 open3d 中进行可视化。 But what I want to do is that one pointcloud stays constant and the other moves in the z direction (that is updating the coordinates of numpy array) without closing the window.但是我想要做的是一个点云保持不变,另一个点云在不关闭窗口的情况下沿 z 方向移动(即更新 numpy 数组的坐标)。

Below is the code in which I pass these two numpy arrays (npa and npa_test) to visualize in open3d.下面是我传递这两个 numpy 数组(npa 和 npa_test)以在 open3d 中进行可视化的代码。 Please note that in the initial lines I store numpy arrays to a .pcd files (since they were extracted from different types of files .asc which open3d doesnot recognize) and then read them using open3d read function.请注意,在初始行中,我将 numpy 数组存储到 .pcd 文件中(因为它们是从 open3d 无法识别的不同类型的文件 .asc 中提取的),然后使用 open3d 读取函数读取它们。 I want to update the one pointcloud geomtry by moving it in z direction and then visualizing it on the same window without closing it.我想通过在 z 方向上移动它来更新一个点云几何,然后在不关闭它的情况下在同一个窗口上可视化它。 This can be done by updating the z cordinates by 1 in for loop as mentioned below.这可以通过在 for 循环中将 z 坐标更新 1 来完成,如下所述。 Please let me know if you have a solution regarding this.如果您对此有解决方案,请告诉我。 Thank you.谢谢你。

def draw(npa,npa_test): def draw(npa,npa_test):

pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(npa)
o3d.io.write_point_cloud("C:/Users/Junaid/Desktop/test.ply", pcd)
pcd_load = o3d.io.read_point_cloud("C:/Users/Junaid/Desktop/test.ply")

pcd1 = o3d.geometry.PointCloud()
pcd1.points = o3d.utility.Vector3dVector(npa_test)
o3d.io.write_point_cloud("C:/Users/Junaid/Desktop/test1.ply", pcd1)
pcd_load1 = o3d.io.read_point_cloud("C:/Users/Junaid/Desktop/test1.ply")

o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Debug)

vis = o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(pcd_load)
vis.add_geometry(pcd_load1)

npa.tolist()

for i in range(len(npa)):

    npa[i][2] = npa[i][2] + 1

    npa=np.asarray(npa, dtype=np.float32)
    pcd = o3d.geometry.PointCloud()
    pcd.points = o3d.utility.Vector3dVector(npa)
    o3d.io.write_point_cloud("C:/Users/Junaid/Desktop/test.ply", pcd)
    pcd_load = o3d.io.read_point_cloud("C:/Users/Junaid/Desktop/test.ply")

    vis.update_geometry(pcd_load)

    vis.poll_events()
    vis.update_renderer()
vis.destroy_window()

I see that you're using npa[i][2] = npa[i][2] + 1 to modify the value which is overkill when you can just use Transformation Matrix to transform the geometry like pcd.transform(np.array([[1,0,0,0],[0,1,0,0],[0,0,1,z_val],[0,0,0,1]])) .我看到你正在使用npa[i][2] = npa[i][2] + 1来修改这个值,当你可以只使用变换矩阵来变换像pcd.transform(np.array([[1,0,0,0],[0,1,0,0],[0,0,1,z_val],[0,0,0,1]]))

Here's easy solution of moving sphere from z=0.5 until 15.0 with increment of 0.005 using open3d.这是使用 open3d 以 0.005 为增量移动球体从 z=0.5 到 15.0 的简单解决方案。

import open3d as o3d
import numpy as np

def create_transform_matrix_from_z(z):
    """ Return transform 4x4 transformation matrix given a Z value """
    result = np.identity(4)
    result[2,3] = z # Change the z
    
    return result

# Create Open3d visualization window
vis = o3d.visualization.Visualizer()
vis.create_window()

# create sphere geometry
sphere1 = o3d.geometry.TriangleMesh.create_sphere()
vis.add_geometry(sphere1)

# create coordinate frame
coordinate_frame = o3d.geometry.TriangleMesh.create_coordinate_frame()
vis.add_geometry(coordinate_frame)

prev_tf = None
for curr_z in np.arange(0.5, 15.0, 0.005):
    # return sphere1 to original position (0,0,0)
    if prev_tf is not None:
        sphere1.transform(np.linalg.inv(prev_tf))

    # transform bazed on curr_z tf
    curr_tf = create_transform_matrix_from_z(curr_z)
    sphere1.transform(curr_tf)

    prev_tf = curr_tf

    vis.update_geometry(sphere1)
    vis.poll_events()
    vis.update_renderer()

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

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