-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShow using open3D.py
85 lines (78 loc) · 5.69 KB
/
Show using open3D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import numpy as np
import open3d as o3d
# Define colors for different classes
class_colors = {
0: [1, 0, 0], # Class 0: Red
1: [0, 1, 0], # Class 1: Green
2: [0, 0, 1] # Class 2: Blue
}
# Define the function to visualize 3D bounding boxes
def visualize_predictions(predictions):
vis = o3d.visualization.Visualizer()
vis.create_window()
mesh_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=1, origin=[0, 0, 0])
for pred in predictions:
labels = pred['labels_3d']
scores = pred['scores_3d']
bboxes = pred['bboxes_3d']
for label, score, bbox in zip(labels, scores, bboxes):
color = class_colors[label]
center = np.array(bbox[:3])
extent = np.array(bbox[3:6]) / 2 # extent should be half of the size
R = np.eye(3) # Identity rotation matrix
box = o3d.geometry.OrientedBoundingBox(center=center, R=R, extent=extent)
box.color = color
vis.add_geometry(box)
vis.add_geometry(mesh_frame)
vis.run()
vis.destroy_window()
# Define the predictions dictionary
predictions = [{'labels_3d': [2, 2, 2, 2, 2, 2, 0, 2, 1, 0, 1, 0, 2, 2, 1, 0,
2, 0, 0, 0],
'scores_3d': [1303.7994384765625, 488.03826904296875,
367.08740234375, 93.24449920654297, 42.8136100769043, 41.14695739746094,
26.154611587524414, 21.48790740966797, 15.851093292236328, 14.59729290008545,
13.851280212402344, 12.468379974365234, 9.640593528747559, 8.768784523010254,
8.549700736999512, 6.60940408706665, 6.532557964324951, 6.353335857391357,
5.915307998657227, 5.801589488983154],
'bboxes_3d': [[-1.2552573680877686, 1.6765952110290527, 8.324033737182617, 3.765509843826294,
1.5764586925506592, 1.5875225067138672, 1.828442096710205],
[8.5192289352417, 1.7063097953796387, 20.11408042907715, 3.662209987640381,
1.571757435798645, 1.6302986145019531, 5.03121280670166],
[0.9986767768859863, 1.6089489459991455, 14.754511833190918, 3.745269536972046,
1.538872241973877, 1.6045942306518555, 5.025647163391113],
[6.606842994689941, 1.4175606966018677, 30.975759506225586, 4.106396198272705,
1.573146104812622, 1.6796820163726807, 1.874942421913147],
[3.6622204780578613, 1.6649692058563232, 5.882591247558594, 3.0675272941589355,
1.4037137031555176, 1.4793691635131836, 4.952999114990234],
[-2.6905479431152344, 1.589762568473816, 3.4678752422332764, 3.837188243865967,
1.5090104341506958, 1.6102190017700195, 4.464268684387207],
[17.996374130249023, 1.494596004486084, 49.30373764038086, 3.9625039100646973,
1.5147329568862915, 1.567384958267212, 1.8674976825714111],
[8.5192289352417, 1.7063097953796387, 20.11408042907715, 3.662209987640381,
1.571757435798645, 1.6302986145019531, 5.03121280670166],
[0.9986767768859863, 1.6089489459991455, 14.754511833190918, 3.745269536972046,
1.538872241973877, 1.6045942306518555, 5.025647163391113],
[-1.2552573680877686, 1.6765952110290527, 8.324033737182617, 3.765509843826294,
1.5764586925506592, 1.5875225067138672, 1.828442096710205],
[8.5192289352417, 1.7063097953796387, 20.11408042907715, 3.662209987640381,
1.571757435798645, 1.6302986145019531, 5.03121280670166],
[10.207386016845703, 1.5982496738433838, 42.153770446777344, 4.025879859924316,
1.5651788711547852, 1.5989911556243896, 5.033463954925537],
[17.50571060180664, 0.9876289367675781, 61.3019905090332, 3.8486618995666504,
1.5177433490753174, 1.6426725387573242, 1.9598616361618042],
[0.9986767768859863, 1.6089489459991455, 14.754511833190918, 3.745269536972046,
1.538872241973877, 1.6045942306518555, 5.025647163391113],
[2.979903221130371, 2.9941956996917725, 9.5604248046875, 0.6669809818267822,
1.7318377494812012, 0.46241262555122375, 1.6722272634506226],
[0.5542198419570923, 3.273090124130249, 11.043625831604004, 3.3030502796173096,
1.5023714303970337, 1.2851146459579468, 1.200079321861267],
[1.8254435062408447, 3.0018205642700195, 9.562115669250488, 0.6640726923942566,
1.724426507949829, 0.4643610417842865, 1.5127475261688232],
[2.399463415145874, 2.983767509460449, 9.503353118896484, 0.674676775932312,
1.730062484741211, 0.46161985397338867, 1.6559252738952637],
[1.9913151264190674, 3.081247568130493, 10.148941993713379, 0.6935614943504333,
1.6272059679031372, 0.46725088357925415, 1.7825157642364502]],
'box_type_3d': 'Camera'}]
# Visualize predictions
visualize_predictions(predictions)