oepn3d python 读取python文件获取指定视角并自动旋转

该代码示例展示了如何利用Open3D库进行非阻塞可视化,通过设置lookat、front和up向量来调整视角,并实现点云的旋转。在迭代过程中更新几何体并捕获图像。set_lookat设置旋转中心,set_front和set_up确定模型的显示方向。
摘要由CSDN通过智能技术生成

本代码修改自open3d官方GitHub的示例代码:

# examples/python/visualization/non_blocking_visualization.py

# examples/python/visualization/non_blocking_visualization.py

import open3d as o3d
import numpy as np
import copy

if __name__ == "__main__":
    # o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Debug)
    point_cloud = o3d.io.read_point_cloud(r"D:\workspace\realsense\test\open3d\point_cloud.ply")

    vis = o3d.visualization.Visualizer()
    vis.create_window()
    vis.add_geometry(point_cloud)
    # vis.add_geometry(target)
    threshold = 0.05
    icp_iteration = 100
    save_image = False

    ctr = vis.get_view_control()
    ctr.set_lookat(np.array([0.0, 0.0, 55.0]))
    ctr.set_up((0, -1, 0))  # set the positive direction of the x-axis as the up direction
    ctr.set_front((-1, 0, 0))  # set the positive direction of the x-axis toward you


    for i in range(icp_iteration):

        R = point_cloud.get_rotation_matrix_from_xyz((np.pi / 180 * 1, 0, 0 * np.pi / 2))
        point_cloud.rotate(R, center=(0.0,0,55.0))
        vis.update_geometry(point_cloud)
        vis.poll_events()
        vis.update_renderer()


        if save_image:
            vis.capture_screen_image("temp_%04d.jpg" % i)
    vis.destroy_window()

set_lookat设置的是:拖动模型旋转时,围绕哪个点进行旋转。

set_front设置的是:垂直指向屏幕外的向量,三维空间中有无数向量,垂直指向屏幕外的只有一个。

set_up设置的是:是设置指向屏幕上方的向量,当设置了垂直指向屏幕外的向量后,模型三维空间中的哪个面和屏幕平行就确定了(垂直屏幕的向量相当于法向量),还剩下一个旋转自由度,设置指向屏幕上方的向量后,模型的显示方式就确定了。

注:set_front和set_up设置的向量应该要满足一定的约束关系,否则可能得不到想要的效果。

参考文献:

1.set_lookat(), set_front(), set_up() usage of VisualControl #2139

2.Open3d学习计划——高级篇 10(自定义可视化)

3.open3d.visualization.ViewControl

4.Open3d之自定义可视化

5.open3d.visualization.draw_geometries

6.官网Visualization Function draw_geometries

7.官网Transformation

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值