point_pillars_detection.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /******************************************************************************
  2. * Copyright 2020 The Apollo Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *****************************************************************************/
  16. #pragma once
  17. #include <deque>
  18. #include <memory>
  19. #include <string>
  20. #include <vector>
  21. #include "pcl/point_cloud.h"
  22. #include "pcl/point_types.h"
  23. #include "modules/perception/base/object.h"
  24. #include "modules/perception/base/point_cloud.h"
  25. #include "modules/perception/lidar/common/lidar_frame.h"
  26. #include "modules/perception/lidar/lib/detection/lidar_point_pillars/point_pillars.h"
  27. namespace apollo {
  28. namespace perception {
  29. namespace lidar {
  30. struct DetectionInitOptions {};
  31. struct DetectionOptions {};
  32. class PointPillarsDetection {
  33. public:
  34. PointPillarsDetection();
  35. ~PointPillarsDetection() = default;
  36. bool Init(const DetectionInitOptions& options = DetectionInitOptions());
  37. bool Detect(const DetectionOptions& options, LidarFrame* frame);
  38. std::string Name() const { return "PointPillarsDetection"; }
  39. private:
  40. void CloudToArray(const base::PointFCloudPtr& pc_ptr,
  41. float* out_points_array,
  42. float normalizing_factor);
  43. void FuseCloud(const base::PointFCloudPtr& out_cloud_ptr,
  44. const std::deque<base::PointDCloudPtr>& fuse_clouds);
  45. std::vector<int> GenerateIndices(int start_index, int size, bool shuffle);
  46. void GetObjects(std::vector<std::shared_ptr<base::Object>>* objects,
  47. const Eigen::Affine3d& pose, std::vector<float>* detections,
  48. std::vector<int>* labels);
  49. base::ObjectSubType GetObjectSubType(int label);
  50. // reference pointer of lidar frame
  51. LidarFrame* lidar_frame_ref_ = nullptr;
  52. std::shared_ptr<base::AttributePointCloud<base::PointF>> original_cloud_;
  53. std::shared_ptr<base::AttributePointCloud<base::PointD>>
  54. original_world_cloud_;
  55. // PointPillars
  56. std::unique_ptr<PointPillars> point_pillars_ptr_;
  57. std::deque<base::PointDCloudPtr> prev_world_clouds_;
  58. base::PointFCloudPtr cur_cloud_ptr_;
  59. // point cloud range
  60. float x_min_;
  61. float x_max_;
  62. float y_min_;
  63. float y_max_;
  64. float z_min_;
  65. float z_max_;
  66. // time statistics
  67. double downsample_time_ = 0.0;
  68. double fuse_time_ = 0.0;
  69. double shuffle_time_ = 0.0;
  70. double cloud_to_array_time_ = 0.0;
  71. double inference_time_ = 0.0;
  72. double collect_time_ = 0.0;
  73. }; // class PointPillarsDetection
  74. } // namespace lidar
  75. } // namespace perception
  76. } // namespace apollo