Open3d(七)——可视化

 亲测代码程序可运行使用,open3d版本0.13.0。

open3d数据资源下载:GitHub - Cobotic/Open3D: Open3D: A Modern Library for 3D Data Processing

代码执行功能有:通过鼠标的缩放,旋转和平移,改变渲染风格和屏幕截图,几何基元,画线,详情请见代码。

'''
Author: dongcidaci
Date: 2021-09-13 08:04:57
LastEditTime: 2021-09-13 08:33:07
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \open3d_code\07_keshihua.py
'''
import open3d as o3d
import numpy as np

#draw_geometries函数
#通过鼠标的缩放,旋转和平移,改变渲染风格和屏幕截图。在窗口界面按 h 打印出全部的函数列表。
pcd = o3d.io.read_point_cloud("test_data/fragment.ply")
o3d.visualization.draw_geometries([pcd], zoom=0.3412,
                                  front=[0.4257, -0.2125, -0.8795],
                                  lookat=[2.6172, 2.0475, 1.532],
                                  up=[-0.0694, -0.9768, 0.2024])

#draw_geometries_with_custom_animation允许程序员去自定义动画轨迹并且在GUI中播放。
# draw_geometries_with_animation_callback和draw_geometries_with_key_callback接受python的回调函数作为输入。回调函数在自动动画循环或按键事件中有用。

#储存视角(视点)
#在一开始,点云的渲染是颠倒的。
#按下ctrl+c保持这个视角后,这个视角将会成为一个保存在粘贴板里面的一个json字符串。
#使用ctrl+v,就可以回到原始视角。
#按 1 将在Phong lighting 和简单颜色渲染之间切换(simple color rendering)。按 2 将展现基于x坐标的颜色。
#颜色映射也可以调整,比如使用shift+4,就可以把颜色从喷墨映射调整到热图映射。

#几何基元(Geometry primitives)
#使用 create_mesh_cubic , create_mesh_sphere和create_mesh_cylinder去创造一个立方体,一个球和一个圆柱体。
# 立方体被涂成红色,球被涂成蓝色,圆柱被涂成绿色。为两个网格去计算法线来支持Phong shading
mesh_box = o3d.geometry.TriangleMesh.create_box(width=1.0,height=1.0,depth=1.0)
mesh_box.compute_vertex_normals()
mesh_box.paint_uniform_color([0.9, 0.1, 0.1])
mesh_sphere = o3d.geometry.TriangleMesh.create_sphere(radius=1.0)
mesh_sphere.compute_vertex_normals()
mesh_sphere.paint_uniform_color([0.1, 0.1, 0.7])
mesh_cylinder = o3d.geometry.TriangleMesh.create_cylinder(radius=0.3,height=4.0)
mesh_cylinder.compute_vertex_normals()
mesh_cylinder.paint_uniform_color([0.1, 0.9, 0.1])
mesh_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.6, origin=[-2, -2, -2])

o3d.visualization.draw_geometries([mesh_box, mesh_sphere, mesh_cylinder, mesh_frame])
o3d.visualization.draw_geometries([mesh_box + mesh_sphere + mesh_cylinder + mesh_frame])

#画线
#要画线的话,需要定义Lineset和创造一组点还有一组边。边是一对点的索引。
points = [
        [0, 0, 0],
        [1, 0, 0],
        [0, 1, 0],
        [1, 1, 0],
        [0, 0, 1],
        [1, 0, 1],
        [0, 1, 1],
        [1, 1, 1],
]
lines = [
        [0, 1],
        [0, 2],
        [1, 3],
        [2, 3],
        [4, 5],
        [4, 6],
        [5, 7],
        [6, 7],
        [0, 4],
        [1, 5],
        [2, 6],
        [3, 7],
]
colors = [[1, 0, 0] for i in range(len(lines))]
line_set = o3d.geometry.LineSet(
    points=o3d.utility.Vector3dVector(points),
    lines=o3d.utility.Vector2iVector(lines),
)
line_set.colors = o3d.utility.Vector3dVector(colors)
o3d.visualization.draw_geometries([line_set],zoom=0.8)


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值