@@ -36,6 +36,7 @@ def __init__(self):
36
36
self .kitti_infos = None
37
37
self .image_idxes = None
38
38
self .dt_annos = None
39
+ self .inference_ctx = None
39
40
40
41
41
42
BACKEND = SecondBackend ()
@@ -67,7 +68,7 @@ def readinfo():
67
68
if not info_path .exists ():
68
69
response ["status" ] = "error"
69
70
response ["message" ] = "ERROR: info file not exist."
70
- print ("ERROR: your info_path is incorrect." )
71
+ print ("ERROR: your root path is incorrect." )
71
72
return response
72
73
BACKEND .info_path = info_path
73
74
with open (info_path , 'rb' ) as f :
@@ -78,7 +79,6 @@ def readinfo():
78
79
79
80
response = jsonify (results = [response ])
80
81
response .headers ['Access-Control-Allow-Headers' ] = '*'
81
- print ("read {} kitti info successful!" .format (len (kitti_infos )))
82
82
return response
83
83
84
84
@app .route ('/api/read_detection' , methods = ['POST' ])
@@ -100,15 +100,14 @@ def read_detection():
100
100
BACKEND .dt_annos = dt_annos
101
101
response = jsonify (results = [response ])
102
102
response .headers ['Access-Control-Allow-Headers' ] = '*'
103
- print ("read {} detection successful!" .format (len (dt_annos )))
104
103
return response
105
104
106
105
107
106
@app .route ('/api/get_pointcloud' , methods = ['POST' ])
108
107
def get_pointcloud ():
109
108
global BACKEND
110
109
instance = request .json
111
- response = {}
110
+ response = {"status" : "normal" }
112
111
if BACKEND .root_path is None :
113
112
return error_response ("root path is not set" )
114
113
if BACKEND .kitti_infos is None :
@@ -119,13 +118,17 @@ def get_pointcloud():
119
118
rect = kitti_info ['calib/R0_rect' ]
120
119
P2 = kitti_info ['calib/P2' ]
121
120
Trv2c = kitti_info ['calib/Tr_velo_to_cam' ]
121
+ img_shape = kitti_info ["img_shape" ] # hw
122
+ wh = np .array (img_shape [::- 1 ])
123
+ whwh = np .tile (wh , 2 )
122
124
if 'annos' in kitti_info :
123
125
annos = kitti_info ['annos' ]
124
126
labels = annos ['name' ]
125
127
num_obj = len ([n for n in annos ['name' ] if n != 'DontCare' ])
126
128
dims = annos ['dimensions' ][:num_obj ]
127
129
loc = annos ['location' ][:num_obj ]
128
130
rots = annos ['rotation_y' ][:num_obj ]
131
+ bbox = annos ['bbox' ][:num_obj ] / whwh
129
132
gt_boxes_camera = np .concatenate (
130
133
[loc , dims , rots [..., np .newaxis ]], axis = 1 )
131
134
gt_boxes = box_np_ops .box_camera_to_lidar (
@@ -138,6 +141,8 @@ def get_pointcloud():
138
141
response ["locs" ] = locs .tolist ()
139
142
response ["dims" ] = dims .tolist ()
140
143
response ["rots" ] = rots .tolist ()
144
+ response ["bbox" ] = bbox .tolist ()
145
+
141
146
response ["labels" ] = labels [:num_obj ].tolist ()
142
147
143
148
v_path = str (Path (BACKEND .root_path ) / kitti_info ['velodyne_path' ])
@@ -152,6 +157,7 @@ def get_pointcloud():
152
157
num_obj = dims .shape [0 ]
153
158
loc = dt_annos ['location' ]
154
159
rots = dt_annos ['rotation_y' ]
160
+ bbox = dt_annos ['bbox' ] / whwh
155
161
labels = dt_annos ['name' ]
156
162
157
163
dt_boxes_camera = np .concatenate (
@@ -166,13 +172,50 @@ def get_pointcloud():
166
172
response ["dt_dims" ] = dims .tolist ()
167
173
response ["dt_rots" ] = rots .tolist ()
168
174
response ["dt_labels" ] = labels .tolist ()
175
+ response ["dt_bbox" ] = bbox .tolist ()
169
176
response ["dt_scores" ] = dt_annos ["score" ].tolist ()
170
177
171
178
# if "score" in annos:
172
179
# response["score"] = score.tolist()
173
180
response = jsonify (results = [response ])
174
181
response .headers ['Access-Control-Allow-Headers' ] = '*'
175
- print ("get point cloud successful, send response!" )
182
+ print ("send response!" )
183
+ return response
184
+
185
+ @app .route ('/api/get_image' , methods = ['POST' ])
186
+ def get_image ():
187
+ global BACKEND
188
+ instance = request .json
189
+ response = {"status" : "normal" }
190
+ if BACKEND .root_path is None :
191
+ return error_response ("root path is not set" )
192
+ if BACKEND .kitti_infos is None :
193
+ return error_response ("kitti info is not loaded" )
194
+ image_idx = instance ["image_idx" ]
195
+ idx = BACKEND .image_idxes .index (image_idx )
196
+ kitti_info = BACKEND .kitti_infos [idx ]
197
+ rect = kitti_info ['calib/R0_rect' ]
198
+ P2 = kitti_info ['calib/P2' ]
199
+ Trv2c = kitti_info ['calib/Tr_velo_to_cam' ]
200
+ if 'img_path' in kitti_info :
201
+ img_path = kitti_info ['img_path' ]
202
+ if img_path != "" :
203
+ image_path = BACKEND .root_path / img_path
204
+ print (image_path )
205
+ with open (str (image_path ), 'rb' ) as f :
206
+ image_str = f .read ()
207
+ response ["image_b64" ] = base64 .b64encode (image_str ).decode ("utf-8" )
208
+ response ["image_b64" ] = 'data:image/{};base64,' .format (image_path .suffix [1 :]) + response ["image_b64" ]
209
+ '''#
210
+ response["rect"] = rect.tolist()
211
+ response["P2"] = P2.tolist()
212
+ response["Trv2c"] = Trv2c.tolist()
213
+ response["L2CMat"] = ((rect @ Trv2c).T).tolist()
214
+ response["C2LMat"] = np.linalg.inv((rect @ Trv2c).T).tolist()
215
+ '''
216
+ print ("send an image with size {}!" .format (len (response ["image_b64" ])))
217
+ response = jsonify (results = [response ])
218
+ response .headers ['Access-Control-Allow-Headers' ] = '*'
176
219
return response
177
220
178
221
@app .route ('/api/build_network' , methods = ['POST' ])
@@ -227,6 +270,9 @@ def inference_by_idx():
227
270
points = box_np_ops .remove_outside_points (
228
271
points , rect , Trv2c , P2 , image_shape )
229
272
print (points .shape [0 ])
273
+ img_shape = kitti_info ["img_shape" ] # hw
274
+ wh = np .array (img_shape [::- 1 ])
275
+ whwh = np .tile (wh , 2 )
230
276
231
277
t = time .time ()
232
278
inputs = BACKEND .inference_ctx .get_inference_input_dict (
@@ -241,6 +287,7 @@ def inference_by_idx():
241
287
loc = dt_annos ['location' ]
242
288
rots = dt_annos ['rotation_y' ]
243
289
labels = dt_annos ['name' ]
290
+ bbox = dt_annos ['bbox' ] / whwh
244
291
245
292
dt_boxes_camera = np .concatenate (
246
293
[loc , dims , rots [..., np .newaxis ]], axis = 1 )
@@ -255,6 +302,7 @@ def inference_by_idx():
255
302
response ["dt_rots" ] = rots .tolist ()
256
303
response ["dt_labels" ] = labels .tolist ()
257
304
response ["dt_scores" ] = dt_annos ["score" ].tolist ()
305
+ response ["dt_bbox" ] = bbox .tolist ()
258
306
259
307
response = jsonify (results = [response ])
260
308
response .headers ['Access-Control-Allow-Headers' ] = '*'
0 commit comments