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、鼠標(biāo)可視化控制
- 鼠標(biāo)左鍵+ 拖拽:可以旋轉(zhuǎn)3D圖形
- Ctrl+鼠標(biāo)左鍵+拖拽:可以移動(dòng)3D圖形
- 按下鼠標(biāo)滾動(dòng)鍵 + 拖拽:也是可以移動(dòng)3D圖形
- Shift + 鼠標(biāo)左鍵 + 拖拽:可以翻轉(zhuǎn)3D圖形
- ?滾動(dòng)鼠標(biāo)滾輪:放大和縮小3D圖形
2、快捷鍵控制
- r / R:重置視圖
- ?Ctrl+C:將當(dāng)前的視圖狀態(tài)復(fù)制到剪貼板
- Ctrl+V:粘貼當(dāng)前視圖的狀態(tài)
如下,是在可視化界面上,復(fù)制的當(dāng)前視圖的狀態(tài)結(jié)果:
{"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āng)前的視圖
- D:進(jìn)行深度捕捉
- O:捕獲當(dāng)前的渲染設(shè)置
- ?? Alt+Enter:在全屏和窗口模式之間切換
4、點(diǎn)云的顏色控制
- 0:默認(rèn)的點(diǎn)云顏色渲染,默認(rèn)點(diǎn)云被渲染成灰色
- 1:渲染點(diǎn)云顏色,和0的時(shí)候效果一樣
- 2:把x的坐標(biāo)值作為顏色渲染
- 3:把y的坐標(biāo)值作為顏色渲染
- 4:把z的坐標(biāo)值作為顏色渲染
- 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()總結(jié)
以上是生活随笔為你收集整理的open3d使用知识拾遗的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 鸟哥的linux私房菜_linux磁盘与
- 下一篇: 故宫为什么是歪的