7
7
from skimage import io as imgio
8
8
9
9
from second .core import box_np_ops
10
+ from second .core .point_cloud .point_cloud_ops import bound_points_jit
10
11
from second .data import kitti_common as kitti
11
12
from second .utils .progress_bar import list_bar as prog_bar
12
13
@@ -18,18 +19,21 @@ def _read_imageset_file(path):
18
19
19
20
def _calculate_num_points_in_gt (data_path , infos , relative_path , remove_outside = True , num_features = 4 ):
20
21
for info in infos :
22
+ pc_info = info ["point_cloud" ]
23
+ image_info = info ["image" ]
24
+ calib = info ["calib" ]
21
25
if relative_path :
22
- v_path = str (pathlib .Path (data_path ) / info ["velodyne_path" ])
26
+ v_path = str (pathlib .Path (data_path ) / pc_info ["velodyne_path" ])
23
27
else :
24
- v_path = info ["velodyne_path" ]
28
+ v_path = pc_info ["velodyne_path" ]
25
29
points_v = np .fromfile (
26
30
v_path , dtype = np .float32 , count = - 1 ).reshape ([- 1 , num_features ])
27
- rect = info [ 'calib/ R0_rect' ]
28
- Trv2c = info [ 'calib/ Tr_velo_to_cam' ]
29
- P2 = info [ 'calib/ P2' ]
31
+ rect = calib [ ' R0_rect' ]
32
+ Trv2c = calib [ ' Tr_velo_to_cam' ]
33
+ P2 = calib [ ' P2' ]
30
34
if remove_outside :
31
35
points_v = box_np_ops .remove_outside_points (points_v , rect , Trv2c , P2 ,
32
- info [ "img_shape " ])
36
+ image_info [ "image_shape " ])
33
37
34
38
# points_v = points_v[points_v[:, 0] > 0]
35
39
annos = info ['annos' ]
@@ -88,20 +92,6 @@ def create_kitti_info_file(data_path,
88
92
print (f"Kitti info val file is saved to { filename } " )
89
93
with open (filename , 'wb' ) as f :
90
94
pickle .dump (kitti_infos_val , f )
91
- """
92
- if create_trainval:
93
- kitti_infos_trainval = kitti.get_kitti_image_info(
94
- data_path,
95
- training=True,
96
- velodyne=True,
97
- calib=True,
98
- image_ids=trainval_img_ids,
99
- relative_path=relative_path)
100
- filename = save_path / 'kitti_infos_trainval.pkl'
101
- print(f"Kitti info trainval file is saved to {filename}")
102
- with open(filename, 'wb') as f:
103
- pickle.dump(kitti_infos_trainval, f)
104
- """
105
95
filename = save_path / 'kitti_infos_trainval.pkl'
106
96
print (f"Kitti info trainval file is saved to { filename } " )
107
97
with open (filename , 'wb' ) as f :
@@ -121,28 +111,33 @@ def create_kitti_info_file(data_path,
121
111
pickle .dump (kitti_infos_test , f )
122
112
123
113
114
+
124
115
def _create_reduced_point_cloud (data_path ,
125
116
info_path ,
126
117
save_path = None ,
127
118
back = False ):
128
119
with open (info_path , 'rb' ) as f :
129
120
kitti_infos = pickle .load (f )
130
121
for info in prog_bar (kitti_infos ):
131
- v_path = info ['velodyne_path' ]
122
+ pc_info = info ["point_cloud" ]
123
+ image_info = info ["image" ]
124
+ calib = info ["calib" ]
125
+
126
+ v_path = pc_info ['velodyne_path' ]
132
127
v_path = pathlib .Path (data_path ) / v_path
133
128
points_v = np .fromfile (
134
129
str (v_path ), dtype = np .float32 , count = - 1 ).reshape ([- 1 , 4 ])
135
- rect = info [ 'calib/ R0_rect' ]
136
- P2 = info [ 'calib/ P2' ]
137
- Trv2c = info [ 'calib/ Tr_velo_to_cam' ]
130
+ rect = calib [ ' R0_rect' ]
131
+ P2 = calib [ ' P2' ]
132
+ Trv2c = calib [ ' Tr_velo_to_cam' ]
138
133
# first remove z < 0 points
139
134
# keep = points_v[:, -1] > 0
140
135
# points_v = points_v[keep]
141
136
# then remove outside.
142
137
if back :
143
138
points_v [:, 0 ] = - points_v [:, 0 ]
144
139
points_v = box_np_ops .remove_outside_points (points_v , rect , Trv2c , P2 ,
145
- info [ "img_shape " ])
140
+ image_info [ "image_shape " ])
146
141
147
142
if save_path is None :
148
143
save_filename = v_path .parent .parent / (v_path .parent .stem + "_reduced" ) / v_path .name
@@ -181,7 +176,6 @@ def create_reduced_point_cloud(data_path,
181
176
_create_reduced_point_cloud (
182
177
data_path , test_info_path , save_path , back = True )
183
178
184
-
185
179
def create_groundtruth_database (data_path ,
186
180
info_path = None ,
187
181
used_classes = None ,
@@ -211,23 +205,27 @@ def create_groundtruth_database(data_path,
211
205
all_db_infos [name ] = []
212
206
group_counter = 0
213
207
for info in prog_bar (kitti_infos ):
214
- velodyne_path = info ['velodyne_path' ]
208
+ pc_info = info ["point_cloud" ]
209
+ image_info = info ["image" ]
210
+ calib = info ["calib" ]
211
+
212
+ velodyne_path = pc_info ['velodyne_path' ]
215
213
if relative_path :
216
214
# velodyne_path = str(root_path / velodyne_path) + "_reduced"
217
215
velodyne_path = str (root_path / velodyne_path )
218
216
num_features = 4
219
- if 'pointcloud_num_features ' in info :
220
- num_features = info [ 'pointcloud_num_features ' ]
217
+ if 'num_features ' in pc_info :
218
+ num_features = pc_info [ 'num_features ' ]
221
219
points = np .fromfile (
222
220
velodyne_path , dtype = np .float32 , count = - 1 ).reshape ([- 1 , num_features ])
223
221
224
- image_idx = info ["image_idx" ]
225
- rect = info [ 'calib/ R0_rect' ]
226
- P2 = info [ 'calib/ P2' ]
227
- Trv2c = info [ 'calib/ Tr_velo_to_cam' ]
222
+ image_idx = image_info ["image_idx" ]
223
+ rect = calib [ ' R0_rect' ]
224
+ P2 = calib [ ' P2' ]
225
+ Trv2c = calib [ ' Tr_velo_to_cam' ]
228
226
if not lidar_only :
229
227
points = box_np_ops .remove_outside_points (points , rect , Trv2c , P2 ,
230
- info [ "img_shape " ])
228
+ image_info [ "image_shape " ])
231
229
232
230
annos = info ["annos" ]
233
231
names = annos ["name" ]
@@ -237,6 +235,7 @@ def create_groundtruth_database(data_path,
237
235
num_obj = np .sum (annos ["index" ] >= 0 )
238
236
rbbox_cam = kitti .anno_to_rbboxes (annos )[:num_obj ]
239
237
rbbox_lidar = box_np_ops .box_camera_to_lidar (rbbox_cam , rect , Trv2c )
238
+ box_np_ops .change_box3d_center_ (rbbox_lidar , [0.5 , 0.5 , 0 ], [0.5 , 0.5 , 0.5 ])
240
239
if bev_only : # set z and h to limits
241
240
assert coors_range is not None
242
241
rbbox_lidar [:, 2 ] = coors_range [2 ]
0 commit comments