-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawMyResult(G)_PVRCNN(R) and GT(K).py
202 lines (179 loc) · 6.82 KB
/
DrawMyResult(G)_PVRCNN(R) and GT(K).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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import pickle
import numpy as np
import open3d as o3d
import torch
def make_3dBox(anno):
boxes = []
lines = [[0, 1], [1, 2], [2, 3], [0, 3], [0, 4], [4, 5],
[5, 6], [6, 7], [4, 7], [1, 5], [2, 6], [3, 7]]
corners3d = boxes_to_corners_3d(anno["boxes_lidar"])
for box in corners3d:
box3d = o3d.geometry.LineSet()
box3d.points = o3d.utility.Vector3dVector(box)
box3d.lines = o3d.utility.Vector2iVector(lines)
box3d.colors = o3d.utility.Vector3dVector(PVRCNNcolor)
boxes.append(box3d)
return boxes
def check_numpy_to_torch(x):
if isinstance(x, np.ndarray):
return torch.from_numpy(x).float(), True
return x, False
def rotate_points_along_z(points, angle):
"""
Args:
points: (B, N, 3 + C)
angle: (B), angle along z-axis, angle increases x ==> y
Returns:
"""
points, is_numpy = check_numpy_to_torch(points)
angle, _ = check_numpy_to_torch(angle)
cosa = torch.cos(angle)
sina = torch.sin(angle)
zeros = angle.new_zeros(points.shape[0])
ones = angle.new_ones(points.shape[0])
rot_matrix = torch.stack((
cosa, sina, zeros,
-sina, cosa, zeros,
zeros, zeros, ones
), dim=1).view(-1, 3, 3).float()
points_rot = torch.matmul(points[:, :, 0:3], rot_matrix)
points_rot = torch.cat((points_rot, points[:, :, 3:]), dim=-1)
return points_rot.numpy() if is_numpy else points_rot
def boxes_to_corners_3d(boxes3d):
"""
7 -------- 4
/| /|
6 -------- 5 .
| | | |
. 3 -------- 0
|/ |/
2 -------- 1
Args:
boxes3d: (N, 7) [x, y, z, dx, dy, dz, heading], (x, y, z) is the box center
Returns:
"""
boxes3d, is_numpy = check_numpy_to_torch(boxes3d)
template = boxes3d.new_tensor((
[1, 1, -1], [1, -1, -1], [-1, -1, -1], [-1, 1, -1],
[1, 1, 1], [1, -1, 1], [-1, -1, 1], [-1, 1, 1],
)) / 2
corners3d = boxes3d[:, None, 3:6].repeat(1, 8, 1) * template[None, :, :]
corners3d = rotate_points_along_z(
corners3d.view(-1, 8, 3), boxes3d[:, 6]).view(-1, 8, 3)
corners3d += boxes3d[:, None, 0:3]
return corners3d.numpy() if is_numpy else corners3d
if __name__ == "__main__":
frame_idx = 1
dirpath = "./data/waymo/waymo_infos_val.pkl"
lines = [[0, 1], [1, 2], [2, 3], [0, 3], [0, 4], [4, 5],
[5, 6], [6, 7], [4, 7], [1, 5], [2, 6], [3, 7]]
fusion_color = [[0, 1, 0] for i in range(len(lines))]
PVRCNNcolor = [[1, 0, 0] for i in range(len(lines))]
## GT BOX######################
with open(dirpath, "rb") as f:
gt_data = pickle.load(f)
print(gt_data[5 * frame_idx]["frame_id"])
gt_boxes = gt_data[5 * frame_idx]["annos"]["gt_boxes_lidar"]
groudTruth_boxes = []
corners3d = boxes_to_corners_3d(gt_boxes)
for box in corners3d:
box3d = o3d.geometry.LineSet()
box3d.points = o3d.utility.Vector3dVector(box)
box3d.lines = o3d.utility.Vector2iVector(lines)
groudTruth_boxes.append(box3d)
############################################
with open("annos3d.pkl", 'rb') as f:
annos3d = pickle.load(f)
with open("frustum.pkl", 'rb') as f:
frustum = pickle.load(f)
lidar_idx = str(5 * frame_idx).zfill(4)
print(annos3d[frame_idx]["frame_id"][:-4]+"/0" +
annos3d[frame_idx]["frame_id"][-3:] + ".npy")
xyz = np.load(
"/home/seongwon/SoftwareCapstone/data/waymo/waymo_processed_data/"+annos3d[frame_idx]["frame_id"][:-4]+"/0" + annos3d[frame_idx]["frame_id"][-3:] + ".npy")
xyz = xyz[:, :3]
segs = []
frustums = []
print(annos3d[frame_idx]["frame_id"])
for f in frustum[frame_idx]["frustum"]:
if f["is_generated"] is True:
segs.append(f)
pcds = []
vecs = []
boxes = []
i = 0
j = 0
k = 0
for seg in segs:
if seg["label"] == 'Pedestrian':
box3d = o3d.geometry.LineSet()
box3d.points = o3d.utility.Vector3dVector(seg["3d_box"])
box3d.lines = o3d.utility.Vector2iVector(lines)
box3d.colors = o3d.utility.Vector3dVector(fusion_color)
boxes.append(box3d)
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(seg["seg"])
pcd.paint_uniform_color([1, 0.6667, 0])
pcds.append(pcd)
i += 1
vecs = vecs+list(seg["seg"])
elif seg["label"] == 'Vehicle':
box3d = o3d.geometry.LineSet()
j += 1
box3d.points = o3d.utility.Vector3dVector(seg["3d_box"])
box3d.lines = o3d.utility.Vector2iVector(lines)
box3d.colors = o3d.utility.Vector3dVector(fusion_color)
boxes.append(box3d)
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(seg["seg"])
pcd.paint_uniform_color([np.random.rand(), np.random.rand(), 0])
pcds.append(pcd)
vecs = vecs+list(seg["seg"])
elif seg["label"] == 'Cyclist':
k += 1
box3d = o3d.geometry.LineSet()
box3d.points = o3d.utility.Vector3dVector(seg["3d_box"])
box3d.lines = o3d.utility.Vector2iVector(lines)
box3d.colors = o3d.utility.Vector3dVector(fusion_color)
boxes.append(box3d)
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(seg["seg"])
pcd.paint_uniform_color([np.random.rand(), np.random.rand(), 0])
pcds.append(pcd)
vecs = vecs+list(seg["seg"])
elif seg["label"] == 'Sign':
box3d = o3d.geometry.LineSet()
# box=fu.make_3d_box(seg["seg"])
box3d.points = o3d.utility.Vector3dVector(seg["3d_box"])
box3d.lines = o3d.utility.Vector2iVector(lines)
box3d.colors = o3d.utility.Vector3dVector(fusion_color)
boxes.append(box3d)
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(seg["seg"])
pcd.paint_uniform_color([0.5, 0.5, 0])
pcds.append(pcd)
vecs = vecs+list(seg["seg"])
box = make_3dBox(annos3d[frame_idx])
cp_xyz = xyz.copy()
all = o3d.geometry.PointCloud()
all.points = o3d.utility.Vector3dVector(cp_xyz)
all.paint_uniform_color([0, 0, 1])
vis = o3d.visualization.Visualizer()
vis.create_window()
for b in groudTruth_boxes:
vis.add_geometry(b)
for b in box:
vis.add_geometry(b)
# for b in boxes:
# vis.add_geometry(b)
vis.add_geometry(all)
# for f in pcds:
# vis.add_geometry(f)
vis.get_render_option().line_width = 100
vis.update_renderer()
print()
print("My predition: {0}".format(i))
print("My Vehicle: {0}".format(j))
print("My Cyclist: {0}".format(k))
vis.run()
vis.destroy_window()