软件工程应用与实践(6)可视化-交互功能

2023-11-07

2021SC@SDUSC 

open3d 

open3d中可视化窗口的交互功能的实现

import numpy as np
import copy
import open3d as o3d


def demo_crop_geometry():
    print("Demo for manual geometry cropping")
    print(
        "1) Press 'Y' twice to align geometry with negative direction of y-axis"
    )
    print("2) Press 'K' to lock screen and to switch to selection mode")
    print("3) Drag for rectangle selection,")
    print("   or use ctrl + left click for polygon selection")
    print("4) Press 'C' to get a selected geometry and to save it")
    print("5) Press 'F' to switch to freeview mode")
    pcd = o3d.io.read_point_cloud("ICP/cloud_bin_0.pcd")
    o3d.visualization.draw_geometries_with_editing([pcd])


def draw_registration_result(source, target, transformation):
    source_temp = copy.deepcopy(source)
    target_temp = copy.deepcopy(target)
    source_temp.paint_uniform_color([1, 0.706, 0])
    target_temp.paint_uniform_color([0, 0.651, 0.929])
    source_temp.transform(transformation)
    o3d.visualization.draw_geometries([source_temp, target_temp])


def pick_points(pcd):
    print("")
    print(
        "1) Please pick at least three correspondences using [shift + left click]"
    )
    print("   Press [shift + right click] to undo point picking")
    print("2) After picking points, press 'Q' to close the window")
    vis = o3d.visualization.VisualizerWithEditing()
    vis.create_window()
    vis.add_geometry(pcd)
    vis.run()  # user picks points
    vis.destroy_window()
    print("")
    return vis.get_picked_points()


def demo_manual_registration():
    print("Demo for manual ICP")
    source = o3d.io.read_point_cloud("ICP/cloud_bin_0.pcd")
    target = o3d.io.read_point_cloud("ICP/cloud_bin_2.pcd")
    print("Visualization of two point clouds before manual alignment")
    draw_registration_result(source, target, np.identity(4))

    # pick points from two point clouds and builds correspondences
    picked_id_source = pick_points(source)
    picked_id_target = pick_points(target)
    assert (len(picked_id_source) >= 3 and len(picked_id_target) >= 3)
    assert (len(picked_id_source) == len(picked_id_target))
    corr = np.zeros((len(picked_id_source), 2))
    corr[:, 0] = picked_id_source
    corr[:, 1] = picked_id_target

    # estimate rough transformation using correspondences
    print("Compute a rough transform using the correspondences given by user")
    p2p = o3d.pipelines.registration.TransformationEstimationPointToPoint()
    trans_init = p2p.compute_transformation(source, target,
                                            o3d.utility.Vector2iVector(corr))

    # point-to-point ICP for refinement
    print("Perform point-to-point ICP refinement")
    threshold = 0.03  # 3cm distance threshold
    reg_p2p = o3d.pipelines.registration.registration_icp(
        source, target, threshold, trans_init,
        o3d.pipelines.registration.TransformationEstimationPointToPoint())
    draw_registration_result(source, target, reg_p2p.transformation)
    print("")


if __name__ == "__main__":
    demo_crop_geometry()
    demo_manual_registration()

执行了两个用户交互应用程序: demo_crop_geometry()demo_manual_registration()

def demo_crop_geometry():
    print("Demo for manual geometry cropping")
    print(
        "1) Press 'Y' twice to align geometry with negative direction of y-axis"
    )
    print("2) Press 'K' to lock screen and to switch to selection mode")
    print("3) Drag for rectangle selection,")
    print("   or use ctrl + left click for polygon selection")
    print("4) Press 'C' to get a selected geometry and to save it")
    print("5) Press 'F' to switch to freeview mode")
    pcd = o3d.io.read_point_cloud("../../test_data/ICP/cloud_bin_0.pcd")
    o3d.visualization.draw_geometries_with_editing([pcd])

这个函数简单读取了一个点云数据然后调用了draw_geometries_with_editing 函数,该函数提供了顶点选择和裁剪功能。

Open3d有一个继承visualizer类的visualizerwithEditing类。它提供了图形用户交互功能。同样的例子在自定义可视化中, visualizerwithEditing()是可以显式的替换掉draw_geometries_with_editing([pcd])。 

上述函数之后可以在open3d中对几何体进行相应的操作最终实现裁剪的效果。 

def pick_points(pcd):
    print("")
    print(
        "1) Please pick at least three correspondences using [shift + left click]"
    )
    print("   Press [shift + right click] to undo point picking")
    print("2) After picking points, press 'Q' to close the window")
    vis = o3d.visualization.VisualizerWithEditing()
    vis.create_window()
    vis.add_geometry(pcd)
    vis.run()  # user picks points
    vis.destroy_window()
    print("")
    return vis.get_picked_points()

函数pick_points(pcd)创造了一个VisualizerwithEditing实例去模仿draw_geometries,创造可视化窗口,添加几何图形,可视化几何图形和结束。VisualizerwithEditing 提供一种新的交互函数get_picked_points(),该函数可以返回用户选取的顶点的索引

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

软件工程应用与实践(6)可视化-交互功能 的相关文章

  • API 端点的 Django 子域配置

    我已经建立了一个 Django 项目 它使用django rest framework提供一些 ReST 功能 网站和其他功能都运行良好 然而有一个小问题 我需要我的 API 端点指向一个不同的子域 例如 当用户访问该网站时 他 她可以根据
  • 与 iexact 一起使用时,Django get_or_create 无法设置字段

    我想用name iexact with get or create尽可能避免用户输入字段的重复 我的提供者模型有一个名称字段 我在其中使用get or create 查找工作正常 但在第一次创建实例时 如下面的 p1 Timber 示例 名
  • Pandas apply 与 np.vectorize 从现有列创建新列的性能

    我正在使用 Pandas 数据框 并希望创建一个新列作为现有列的函数 我还没有看到关于之间速度差异的很好的讨论df apply and np vectorize 所以我想我会在这里问 熊猫apply 功能很慢 根据我的测量 在一些实验中如下
  • 为什么我不能使用“exclude”从 python 轮子中排除“tests”目录?

    考虑以下包结构 与以下setup py内容 from setuptools import setup find packages setup name dfl client packages find packages exclude te
  • 编辑 scikit-learn 决策树

    我想编辑 sklearn DecisionTree 例如改变条件或切割节点 叶子等 但似乎没有功能可以做到这一点 如果我可以导出到文件 编辑它以导入 如何编辑决策树 环境 Windows 10 python3 3 sklearn 0 17
  • Python:记录垃圾收集器

    我有一个 python 应用程序 有一些性能问题 我想将垃圾收集器的事件 特别是何时调用 添加到我的日志中 是否可以 thanks http docs python org library gc html gc set debug http
  • 子进程改变目录

    我想在子目录 超级目录中执行脚本 我需要首先进入该子目录 超级目录 我无法得到subprocess进入我的子目录 tducin localhost Projekty tests ve python Python 2 7 4 default
  • Python + PostgreSQL + 奇怪的ascii = UTF8编码错误

    我有包含字符的 ascii 字符串 x80 代表欧元符号 gt gt gt print x80 当将包含该字符的字符串数据插入数据库时 我得到 psycopg2 DataError invalid byte sequence for enc
  • Python,将迭代函数变成递归函数

    我创建了一个输出 4 3 2 1 0 1 2 3 4 的迭代函数 def bounce2 n s n for i in range n print n n n 1 if n lt 0 for i in range s 1 print n n
  • Python的reduce()短路了吗?

    If I do result reduce operator and False 1000 得到第一个结果后它会停止吗 自从False anything False 相似地 result reduce operator or True 10
  • Python 正则表达式部分匹配或“hitEnd”

    我正在编写一个扫描器 因此我将任意字符串与正则表达式规则列表进行匹配 如果我可以模拟 Java hitEnd 功能 不仅知道正则表达式何时不匹配 还知道何时匹配 这将非常有用 can t匹配 当正则表达式匹配器在决定拒绝输入之前到达输入末尾
  • Django 的 URL 覆盖率测试为 0%,为什么?

    使用姜戈鼻子 我对 URL 进行了测试 但 URL 覆盖率仍然为 0 为什么 python manage py 测试配置文件 这是我的报道 Name Stmts Miss Cover Missing profiles 0 0 100 pro
  • Matplotlib 图例不工作

    自从升级 matplotlib 以来 每当尝试创建图例时 我都会收到以下错误 usr lib pymodules python2 7 matplotlib legend py 610 UserWarning Legend does not
  • 如何在 Python 中从 HTML 页面中提取 URL [关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我必须用Python 编写一个网络爬
  • 求解不等式系统时“多项式错误:仅允许使用单变量多项式”

    我想找到以下两个常数的区间cons1 and cons2我写了下面的代码 from sympy import Poly from sympy import Abs from sympy solvers inequalities import
  • Jupyter Notebook:没有名为 pandas 的模块

    我搜索了其他问题 但没有找到任何有帮助的内容 大多数只是建议您使用 conda 或 pip 安装 pandas 在我的 jupyter 笔记本中 我试图导入 pandas import pandas as pd 但我收到以下错误 Modul
  • Spyder 如何在同一线程的后台运行 asyncio 事件循环(或者确实如此?)

    我已经研究 asyncio 模块 功能几天了 因为我想将它用于我的应用程序的 IO 绑定部分 并且我认为我现在对它的工作原理有一个合理的理解 或者在至少我认为我已经理解了以下内容 任一时刻 任一线程中只能运行一个异步事件循环 一旦一切都设置
  • 在 Python 的 Textmate 中突出显示尾随空格?

    我想做类似的事情this http remysharp com 2008 03 30 trailing white space in textmate Textmate 提示 这样当我在 Python 中编写代码时 尾随空白总是以某种方式突
  • 如何使用Featuretools按列值从单个数据框中的多个列创建特征?

    我正在尝试根据之前的结果来预测足球比赛的结果 我在 Windows 上运行 Python 3 6 并使用 Featuretools 0 4 1 假设我有以下代表结果历史记录的数据框 原始数据框 https i stack imgur com
  • 获取调用者文件的绝对路径

    假设我在不同的目录中有两个文件 1 py 比如说 在C FIRST FOLDER 1 py and 2 py 比如说 在C SECOND FOLDER 2 py 文件1 py进口2 py using sys path insert 0 pa

随机推荐