181 {
182
183 if (frame == nullptr) {
184 AERROR <<
"Input null frame ptr.";
185 return false;
186 }
187 if (frame->cloud == nullptr) {
188 AERROR <<
"Input null frame cloud.";
189 return false;
190 }
191 if (frame->cloud->size() == 0) {
192 AERROR <<
"Input none points.";
193 return false;
194 }
195
196
197 original_cloud_ = frame->cloud;
198 original_world_cloud_ = frame->world_cloud;
199 lidar_frame_ref_ = frame;
200
201
203
205 AERROR <<
"Failed to set device to gpu "
207 return false;
208 }
209
210 Timer timer;
211
212 int num_points;
213 cur_cloud_ptr_ = std::shared_ptr<base::PointFCloud>(
215
217 cur_cloud_ptr_->CopyPointCloud(*original_cloud_, frame->roi_indices);
218 }
219
220
224 cur_cloud_ptr_, downsample_beams_cloud_ptr,
226 cur_cloud_ptr_ = downsample_beams_cloud_ptr;
227 } else {
228 AWARN <<
"Down-sample beams factor must be >= 1. Cancel down-sampling."
229 " Current factor: "
231 }
232 }
233
234
236 DownSampleOptions down_sample_options;
237 ACHECK(down_sample_ !=
nullptr);
238 down_sample_->Process(down_sample_options, cur_cloud_ptr_);
239 }
240
241 downsample_time_ = timer.toc(true);
242 num_points = cur_cloud_ptr_->size();
243 AINFO <<
"num points before fusing: " << num_points;
244
245
246 cur_cloud_ptr_->mutable_points_timestamp()->assign(cur_cloud_ptr_->size(),
247 0.0);
250
251 while (!prev_world_clouds_.empty() &&
252 frame->timestamp - prev_world_clouds_.front()->get_timestamp() >
254 prev_world_clouds_.pop_front();
255 }
256
258 std::make_shared<base::PointDCloud>();
259 for (size_t i = 0; i < cur_cloud_ptr_->size(); ++i) {
260 auto &pt = cur_cloud_ptr_->at(i);
261 Eigen::Vector3d trans_point(pt.x, pt.y, pt.z);
264 world_point.x = trans_point(0);
265 world_point.y = trans_point(1);
266 world_point.z = trans_point(2);
267 world_point.intensity = pt.intensity;
268 cur_world_cloud_ptr->push_back(world_point);
269 }
270 cur_world_cloud_ptr->set_timestamp(frame->timestamp);
271
272
273 for (auto &prev_world_cloud_ptr : prev_world_clouds_) {
274 num_points += prev_world_cloud_ptr->size();
275 }
276 FuseCloud(cur_cloud_ptr_, prev_world_clouds_);
277
278
279 while (static_cast<int>(prev_world_clouds_.size()) >=
281 prev_world_clouds_.pop_front();
282 }
283 prev_world_clouds_.emplace_back(cur_world_cloud_ptr);
284 }
285 fuse_time_ = timer.toc(true);
286
287
289 num_points =
291 std::vector<int> point_indices = GenerateIndices(0, num_points, true);
294 cur_cloud_ptr_ = shuffle_cloud_ptr;
295 }
296 shuffle_time_ = timer.toc(true);
297
298
299 std::vector<float> points_data(num_points *
301
302 CloudToArray(cur_cloud_ptr_, points_data.data(),
304 cloud_to_array_time_ = timer.toc(true);
305
306 auto input_data_blob = inference_->get_blob(input_blob_names_.at(0));
307 auto output_bbox_blob = inference_->get_blob(output_blob_names_.at(0));
308 auto output_score_blob = inference_->get_blob(output_blob_names_.at(1));
309 auto output_label_blob = inference_->get_blob(output_blob_names_.at(2));
310
311 std::vector<int> points_shape{num_points,
313 input_data_blob->Reshape(points_shape);
314 float *data_ptr = input_data_blob->mutable_cpu_data();
315 memcpy(data_ptr, points_data.data(), points_data.size() * sizeof(float));
316
317 inference_->Infer();
318
319 inference_time_ = timer.toc(true);
320
321
322 std::vector<float> out_detections;
323 std::vector<int64_t> out_labels;
324 std::vector<float> out_scores;
325
326
327
328
329
330 FilterDiffScore(output_bbox_blob, output_label_blob, output_score_blob,
331 &out_detections, &out_labels, &out_scores);
332
333 GetObjects(frame->lidar2world_pose, out_detections,
334 out_labels, out_scores, &frame->segmented_objects);
335
336 std::stringstream sstr;
337 sstr << "[CenterPointDetection BeforeNMS] "
338 << std::to_string(frame->timestamp)
339 << " objs: " << frame->segmented_objects.size() << std::endl;
340 for (auto obj : frame->segmented_objects) {
341 sstr << "id = " << obj->id << ": " << obj->center(0) << ", "
342 << obj->center(1) << ", " << obj->center(2) << ", "
343 << obj->size(0) << ", " << obj->size(1) << ", "
344 << obj->size(2) << ", " << obj->theta << ", "
345 << static_cast<int>(obj->type) << ", "
346 << obj->confidence << std::endl;
347 }
349
351 FilterObjectsbyPoints(&frame->segmented_objects);
352 }
353
355 if (diff_class_nms_) {
356 FilterObjectsbyClassNMS(&frame->segmented_objects);
357 }
359 nms_time_ = timer.toc(true);
360
361
363 FilterObjectsbySemanticType(&frame->segmented_objects);
364 }
365
366 FilterForegroundPoints(&frame->segmented_objects);
367
368 SetPointsInROI(&frame->segmented_objects);
369
370 postprocess_time_ = timer.toc(true);
371
372 AINFO <<
"CenterPoint: "
373 << "\n"
374 << "down sample: " << downsample_time_ << "\t"
375 << "fuse: " << fuse_time_ << "\t"
376 << "shuffle: " << shuffle_time_ << "\t"
377 << "cloud_to_array: " << cloud_to_array_time_ << "\t"
378 << "inference: " << inference_time_ << "\t"
379 << "postprocess: " << postprocess_time_ << "\t"
380 << "nms: " << nms_time_ << "\t";
381
382 std::stringstream ssstr;
383 ssstr << "[CenterPointDetection AfterNMS] "
384 << std::to_string(frame->timestamp)
385 << " objs: " << frame->segmented_objects.size() << std::endl;
386 for (auto obj : frame->segmented_objects) {
387 ssstr << "id = " << obj->id << ": " << obj->center(0) << ", "
388 << obj->center(1) << ", " << obj->center(2) << ", "
389 << obj->size(0) << ", " << obj->size(1) << ", "
390 << obj->size(2) << ", " << obj->theta << ", "
391 << static_cast<int>(obj->type) << std::endl;
392 }
394
395 return true;
396}
bool DownSamplePointCloudBeams(base::PointFCloudPtr cloud_ptr, base::PointFCloudPtr out_cloud_ptr, int downsample_factor)
AttributePointCloud< PointF > PointFCloud
std::shared_ptr< PointDCloud > PointDCloudPtr
std::shared_ptr< PointFCloud > PointFCloudPtr
optional bool enable_downsample_beams
optional bool enable_fuse_frames
optional bool enable_roi_outside_removal
optional int32 max_num_points
optional int32 num_point_feature
optional bool enable_downsample_pointcloud
optional bool enable_shuffle_points
optional double fuse_time_interval
optional int32 downsample_beams_factor
optional double normalizing_factor
optional int32 num_fuse_frames
Eigen::Affine3d lidar2world_pose
std::vector< std::shared_ptr< base::Object > > segmented_objects
optional bool filter_by_points
optional bool filter_by_semantic_type
optional common::PointCloudPreProcess preprocess