open3d使用知识拾遗
一 、open3d可视化中的一些使用
在可视化界面,按下h / H
就可以在命令行下看到open3d
的一下使用操作:
[Open3D INFO] -- Mouse view control --
[Open3D INFO] Left button + drag : Rotate.
[Open3D INFO] Ctrl + left button + drag : Translate.
[Open3D INFO] Wheel button + drag : Translate.
[Open3D INFO] Shift + left button + drag : Roll.
[Open3D INFO] Wheel : Zoom in/out.
[Open3D INFO]
[Open3D INFO] -- Keyboard view control --
[Open3D INFO] [/] : Increase/decrease field of view.
[Open3D INFO] R : Reset view point.
[Open3D INFO] Ctrl/Cmd + C : Copy current view status into the clipboard.
[Open3D INFO] Ctrl/Cmd + V : Paste view status from clipboard.
[Open3D INFO]
[Open3D INFO] -- General control --
[Open3D INFO] Q, Esc : Exit window.
[Open3D INFO] H : Print help message.
[Open3D INFO] P, PrtScn : Take a screen capture.
[Open3D INFO] D : Take a depth capture.
[Open3D INFO] O : Take a capture of current rendering settings.
[Open3D INFO] Alt + Enter : Toggle between full screen and windowed mode.
[Open3D INFO]
[Open3D INFO] -- Render mode control --
[Open3D INFO] L : Turn on/off lighting.
[Open3D INFO] +/- : Increase/decrease point size.
[Open3D INFO] Ctrl + +/- : Increase/decrease width of geometry::LineSet.
[Open3D INFO] N : Turn on/off point cloud normal rendering.
[Open3D INFO] S : Toggle between mesh flat shading and smooth shading.
[Open3D INFO] W : Turn on/off mesh wireframe.
[Open3D INFO] B : Turn on/off back face rendering.
[Open3D INFO] I : Turn on/off image zoom in interpolation.
[Open3D INFO] T : Toggle among image render:
[Open3D INFO] no stretch / keep ratio / freely stretch.
[Open3D INFO]
[Open3D INFO] -- Color control --
[Open3D INFO] 0..4,9 : Set point cloud color option.
[Open3D INFO] 0 - Default behavior, render point color.
[Open3D INFO] 1 - Render point color.
[Open3D INFO] 2 - x coordinate as color.
[Open3D INFO] 3 - y coordinate as color.
[Open3D INFO] 4 - z coordinate as color.
[Open3D INFO] 9 - normal as color.
[Open3D INFO] Ctrl + 0..4,9: Set mesh color option.
[Open3D INFO] 0 - Default behavior, render uniform gray color.
[Open3D INFO] 1 - Render point color.
[Open3D INFO] 2 - x coordinate as color.
[Open3D INFO] 3 - y coordinate as color.
[Open3D INFO] 4 - z coordinate as color.
[Open3D INFO] 9 - normal as color.
[Open3D INFO] Shift + 0..4 : Color map options.
[Open3D INFO] 0 - Gray scale color.
[Open3D INFO] 1 - JET color map.
[Open3D INFO] 2 - SUMMER color map.
[Open3D INFO] 3 - WINTER color map.
[Open3D INFO] 4 - HOT color map.
1、鼠标可视化控制
- 鼠标左键+ 拖拽:可以旋转3D图形
- Ctrl+鼠标左键+拖拽:可以移动3D图形
- 按下鼠标滚动键 + 拖拽:也是可以移动3D图形
- Shift + 鼠标左键 + 拖拽:可以翻转3D图形
- 滚动鼠标滚轮:放大和缩小3D图形
2、快捷键控制
- r / R:重置视图
- Ctrl+C:将当前的视图状态复制到剪贴板
- Ctrl+V:粘贴当前视图的状态
如下,是在可视化界面上,复制的当前视图的状态结果:
{"class_name" : "ViewTrajectory","interval" : 29,"is_loop" : false,"trajectory" : [{"boundingbox_max" : [ 15.840000152587891, 77.004997253417969, 2.0550000667572021 ],"boundingbox_min" : [ -32.341999053955078, -0.059999999999999998, -2.1480000019073486 ],"field_of_view" : 60.0,"front" : [ -0.29917197347768476, -0.57001121176759129, 0.76523417902280733 ],"lookat" : [ 6.7522963660420237, 29.49152986284853, -10.538585241474523 ],"up" : [ 0.40106739384242224, 0.65256627539464518, 0.64288583886566331 ],"zoom" : 0.45999999999999974}],"version_major" : 1,"version_minor" : 0
}
3、一般的控制
[Open3D INFO] – General control –
[Open3D INFO] Q, Esc : Exit window.
[Open3D INFO] H : Print help message.
[Open3D INFO] P, PrtScn : Take a screen capture.
[Open3D INFO] D : Take a depth capture.
[Open3D INFO] O : Take a capture of current rendering settings.
[Open3D INFO] Alt + Enter : Toggle between full screen and windowed mode.
[Open3D INFO]
- Q或Esc:退出图形显示
- H:打印帮助信息
- P或PrtScn:截图当前的视图
- D:进行深度捕捉
- O:捕获当前的渲染设置
- Alt+Enter:在全屏和窗口模式之间切换
4、点云的颜色控制
0
:默认的点云颜色渲染,默认点云被渲染成灰色
1
:渲染点云颜色,和0的时候效果一样2
:把x的坐标值作为颜色渲染3
:把y的坐标值作为颜色渲染4
:把z的坐标值作为颜色渲染9
:正常颜色,也是灰色
二、Draw Bounding Boxes on open3D
From <How to draw bounding boxes and update them real time in python>
For visualizing the bounding boxes, you'll have to convert the boxes from
[cx, cy, cz, rot_z, length, width, height]
to an array of points that represent the 8 corners of the box.
You can use a function like this, that takes an array containing [x,y,z,h,w,l,r]
, and returns an [8, 3]
matrix that represents the [x, y, z]
for each 8 corners of the box:
def box_center_to_corner(box_center):# To returncorner_boxes = np.zeros((8, 3))translation = box[0:3]h, w, l = size[3], size[4], size[5]rotation = box[6]# Create a bounding box outlinebounding_box = np.array([[-l/2, -l/2, l/2, l/2, -l/2, -l/2, l/2, l/2],[w/2, -w/2, -w/2, w/2, w/2, -w/2, -w/2, w/2],[-h/2, -h/2, -h/2, -h/2, h/2, h/2, h/2, h/2]])# Standard 3x3 rotation matrix around the Z axisrotation_matrix = np.array([[np.cos(rotation), -np.sin(rotation), 0.0],[np.sin(rotation), np.cos(rotation), 0.0],[0.0, 0.0, 1.0]])# Repeat the [x, y, z] eight timeseight_points = np.tile(translation, (8, 1))# Translate the rotated bounding box by the# original center position to obtain the final boxcorner_box = np.dot(rotation_matrix, bounding_box) + eight_points.transpose()return corner_box.transpose()
Once you've converted your bounding boxes to [8, 3]
matrices representing the corners, you can display them in Open3D by using the LineSet
object:
# Our lines span from points 0 to 1, 1 to 2, 2 to 3, etc...
lines = [[0, 1], [1, 2], [2, 3], [0, 3],[4, 5], [5, 6], [6, 7], [4, 7],[0, 4], [1, 5], [2, 6], [3, 7]]# Use the same color for all lines
colors = [[1, 0, 0] for _ in range(len(lines))]line_set = o3d.geometry.LineSet()
line_set.points = o3d.utility.Vector3dVector(corner_box)
line_set.lines = o3d.utility.Vector2iVector(lines)
line_set.colors = o3d.utility.Vector3dVector(colors)# Create a visualization object and window
vis = o3d.visualization.Visualizer()
vis.create_window()# Display the bounding boxes:
vis.add_geometry(corner_box)
In terms of updating the bounding boxes each time step, refer to the documentation for the Open3D Visualizer object, where there are methods for clearing all geometry (clear_geometries()
), clearing a specific geometry (remove_geometry(geometry)
), etc.
import os
import numpy as np
import struct
import open3d
import math
from Save_KITTI_Format.dataexport import *
def read_bin_velodyne(path):pc_list=[]with open(path,'rb') as f:content=f.read()pc_iter=struct.iter_unpack('ffff',content)for idx,point in enumerate(pc_iter):pc_list.append([point[0],point[1],point[2],point[3]])return np.asarray(pc_list,dtype=np.float32)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) Afther picking points, press q for close the window")vis = open3d.visualization.VisualizerWithEditing()vis.create_window()vis.add_geometry(pcd)vis.run() # user picks pointsvis.destroy_window()print("")return vis.get_picked_points()def box_center_to_corner(box):# To returncorner_boxes = np.zeros((8, 3))translation = box[0:3]h, w, l = box[3], box[4], box[5]rotation = box[6]# Create a bounding box outlinebounding_box = np.array([[-l/2, -l/2, l/2, l/2, -l/2, -l/2, l/2, l/2],[w/2, -w/2, -w/2, w/2, w/2, -w/2, -w/2, w/2],[-h/2, -h/2, -h/2, -h/2, h/2, h/2, h/2, h/2]])# Standard 3x3 rotation matrix around the Z axisrotation_matrix = np.array([[np.cos(rotation), -np.sin(rotation), 0.0],[np.sin(rotation), np.cos(rotation), 0.0],[0.0, 0.0, 1.0]])# Repeat the [x, y, z] eight timeseight_points = np.tile(translation, (8, 1))# Translate the rotated bounding box by the# original center position to obtain the final boxcorner_box = np.dot(rotation_matrix, bounding_box) + eight_points.transpose()return corner_box.transpose()def main():# root_dir='/media/gac/新加卷/KITTI_win/KITTI/gt_database'# root_dir='/media/gac/新加卷/KITTI_win/Gkitti_test/GkittiTest_gt_database'root_dir='/media/gac/新加卷/KITTI_win/GACdata_2_kitti/GACdata_gt_database'filename = '0_TRUCK_BUS_1.bin'# filename = '0_TRUCK_BUS_2.bin'# root_dir='/media/gac/新加卷/KITTI_win/Gkitti_test/training/velodyne'# filename='000000.bin'#root_dir='/media/gac/新加卷/KITTI_win/GACdata_2_kitti/training/velodyne'filename='003363.bin'path=os.path.join(root_dir, filename)example=read_bin_velodyne(path)print(example)# From numpy to Open3Dpcd = open3d.open3d.geometry.PointCloud()pcd.points= open3d.open3d.utility.Vector3dVector(example[:,0:3])# intensities=example[:,3]# open3d.open3d.visualization.draw_geometries([pcd])# picked_id_target = pick_points(pcd)"""SHOW 3D Bounding Box on Open3D"""'''box: [x,y,z,h,w,l,r]Box Center: [x, y, z] Box Size: [h,w,l] (h:z_size, w: y_size, l: x_size )+x (r=0)^|(r-->pi/2) | +y <__________|___________-y (r=-pi/2) ||-x (r=pi)'''KITTI_label=[3.4026522636413574,3.0408647060394287,9.162651062011719,3.3855819702148438,1.8919707536697388,-2.6695749759674072,-1.5188624539691975]box=[KITTI_label[5],-KITTI_label[3],-KITTI_label[4]+KITTI_label[0]/2.0,KITTI_label[0],KITTI_label[1],KITTI_label[2],KITTI_label[6]*(-1)-math.pi/2.0]corner_box=box_center_to_corner(box)lines = [[0, 1], [1, 2], [2, 3], [0, 3],[4, 5], [5, 6], [6, 7], [4, 7],[0, 4], [1, 5], [2, 6], [3, 7]]# Use the same color for all linescolors = [[1, 0, 0] for _ in range(len(lines))]line_set = open3d.geometry.LineSet()line_set.points = open3d.utility.Vector3dVector(corner_box)line_set.lines = open3d.utility.Vector2iVector(lines)line_set.colors = open3d.utility.Vector3dVector(colors)# open3d.open3d.visualization.draw_geometries([line_set])# # Create a visualization object and windowvis = open3d.visualization.Visualizer()vis.create_window()## # Display the bounding boxes:vis.add_geometry(line_set)open3d.open3d.visualization.draw_geometries([pcd,line_set])if __name__=="__main__":main()
open3d使用知识拾遗相关推荐
- 洗礼灵魂,修炼python(85)-- 知识拾遗篇 —— 深度剖析让人幽怨的编码
编码 这篇博文的主题是,编码问题,老生常谈的问题了对吧?从我这一套的文章来看,前面已经提到好多次编码问题了,的确这个确实很重要,这可是难道了很多能人异士的,当你以为你学懂了,在研究爬虫时你发现你错了, ...
- [笔记]Open3D基础知识及例程demo
最近需要进行多张点云图合并+生成mesh,发现Open3D是一个不错的工具. 文中所有用到的代码和数据我上传到了: 百度网盘: 链接:https://pan.baidu.com/s/1ra3bh6ld ...
- python基础知识拾遗
python菜鸟教程 文章目录 基础教程 简介 基础语法(略) 变量类型 标准数据类型 数字 字符串 列表 元组 字典 数据类型转换 运算符 算术运算符 赋值运算符 位运算符(?) 逻辑运算符 成员运 ...
- python基础拾遗
Python-python基础02 本章内容 模块初识 数据运算 .pyc是个什么鬼? 入门知识拾遗 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 一.模块初识 Pytho ...
- 大志非才不就,大才非学不成—我的博文资源汇总
零.苦逼码农的自我修养系列 PS:为什么此部分序号是零而不是一?因为这是作为一个码农所应该具有的基础之中的基础,要想做个好码农,此部分还得花大力气啃书啊,这决定了我们看待计算机程序的高度. 0.1 数 ...
- Python总结:Python基础(一)
Python之路[第二篇]:Python基础(一) 入门知识拾遗 一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. 1 2 3 if 1==1: name ...
- 《JavaScript凌厉开发 Ext详解与实践》的目录
目 录 第1章 开篇.... 1 1.1 网络开发浪潮..... 2 1.2 RIA三足鼎立..... 2 1.2.1 Flex和OpenLaszlo.. 3 1.2.2 Faces客 ...
- 大志非才不就,大才非学不成—博文资源汇总
零.苦逼码农的自我修养系列 PS:为什么此部分序号是零而不是一?因为这是作为一个码农所应该具有的基础之中的基础,要想做个好码农,此部分还得花大力气啃书啊,这决定了我们看待计算机程序的高度. 0.1 数 ...
- Python之路【第二篇】:Python基础(一)
Python之路[第二篇]:Python基础(一) 入门知识拾遗 一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. 1 2 3 if 1==1: name ...
最新文章
- 别在 Java 代码里乱打日志了,这才是正确的日志打印姿势!
- 使用PHP处理POST上传时$_FILES数组为何为空
- linux mysql 5.7 双机热备_2017年5月5日 星红桉liunx动手实践mysql 主主双机热备
- 创客更新装备 动态规划
- 8.Using Categorical Data with One Hot Encoding
- Intent介绍及Intent在Activity中的使用方法
- unix 登录mysql_实例分析mysql用户登录。
- java的获取声音振幅_录音获取声音振幅波形显示
- ocs添加仓库受限问题
- eclipse 的Java Resource文件夹显示有错,可是文件夹下面的文件没有提示错误,这是怎么回事?怎么解决?
- 在centos 7上自动安装starUML,且破解之。
- 预处理criteo数据集以预测广告的点击率
- IBX TableVew
- showtext matlab,使用MATLAB 2019 App Design 工具设计一个 电子日记App
- 三相电机驱动电路详解
- 【Opencv】Python+openCV实现全景图拼接(左右两张图片拼接成一张全景图)
- JAVA EE:1~5章选择题
- YAML——基本语法
- 藏在GPT背后的治理分歧:那些赞同和反对的人们|AI百态(下篇)
- 下载微信文章中腾讯视频的方法