Apollo 11.0
自动驾驶开放平台
apollo::perception::lidar::MaskPillarsDetection类 参考

#include <mask_pillars_detection.h>

类 apollo::perception::lidar::MaskPillarsDetection 继承关系图:
apollo::perception::lidar::MaskPillarsDetection 的协作图:

Public 成员函数

 MaskPillarsDetection ()
 Construct a new Mask Pillars Detection object
 
virtual ~MaskPillarsDetection ()=default
 Destroy the Mask Pillars Detection object
 
bool Init (const LidarDetectorInitOptions &options=LidarDetectorInitOptions()) override
 Init of Mask Pillars Detection object
 
bool Detect (const LidarDetectorOptions &options, LidarFrame *frame) override
 Detect foregorund objects using maskpillars
 
std::string Name () const override
 Name of Mask Pillars Detection module
 
- Public 成员函数 继承自 apollo::perception::lidar::BaseLidarDetector
 BaseLidarDetector ()=default
 Construct a new Base Lidar Detector object
 
virtual ~BaseLidarDetector ()=default
 Destroy the Base Lidar Detector object
 

详细描述

在文件 mask_pillars_detection.h 第 38 行定义.

构造及析构函数说明

◆ MaskPillarsDetection()

apollo::perception::lidar::MaskPillarsDetection::MaskPillarsDetection ( )

Construct a new Mask Pillars Detection object

在文件 mask_pillars_detection.cc 第 40 行定义.

41 : x_min_(Params::kMinXRange),
42 x_max_(Params::kMaxXRange),
43 y_min_(Params::kMinYRange),
44 y_max_(Params::kMaxYRange),
45 z_min_(Params::kMinZRange),
46 z_max_(Params::kMaxZRange) {}
static constexpr float kMaxYRange
Definition params.h:36
static constexpr float kMinYRange
Definition params.h:33
static constexpr float kMaxZRange
Definition params.h:37
static constexpr float kMinXRange
Definition params.h:32
static constexpr float kMinZRange
Definition params.h:34
static constexpr float kMaxXRange
Definition params.h:35

◆ ~MaskPillarsDetection()

virtual apollo::perception::lidar::MaskPillarsDetection::~MaskPillarsDetection ( )
virtualdefault

Destroy the Mask Pillars Detection object

成员函数说明

◆ Detect()

bool apollo::perception::lidar::MaskPillarsDetection::Detect ( const LidarDetectorOptions &  options,
LidarFrame *  frame 
)
overridevirtual

Detect foregorund objects using maskpillars

参数
optionslidar detector options
framelidar frame
返回
true
false

实现了 apollo::perception::lidar::BaseLidarDetector.

在文件 mask_pillars_detection.cc 第 94 行定义.

95 {
96 // check input
97 if (frame == nullptr) {
98 AERROR << "Input null frame ptr.";
99 return false;
100 }
101 if (frame->cloud == nullptr) {
102 AERROR << "Input null frame cloud.";
103 return false;
104 }
105 if (frame->cloud->size() == 0) {
106 AERROR << "Input none points.";
107 return false;
108 }
109
110 // record input cloud and lidar frame
111 original_cloud_ = frame->cloud;
112 original_world_cloud_ = frame->world_cloud;
113 lidar_frame_ref_ = frame;
114
115 // check output
116 frame->segmented_objects.clear();
117
118 if (cudaSetDevice(param_.preprocess().gpu_id()) != cudaSuccess) {
119 AERROR << "Failed to set device to gpu " << param_.preprocess().gpu_id();
120 return false;
121 }
122
123 Timer timer;
124
125 int num_points;
126 cur_cloud_ptr_ = std::shared_ptr<base::PointFCloud>(
127 new base::PointFCloud(*original_cloud_));
128
129 // down sample the point cloud through filtering beams
130 if (param_.preprocess().enable_downsample_beams()) {
131 base::PointFCloudPtr downsample_beams_cloud_ptr(new base::PointFCloud());
133 original_cloud_, downsample_beams_cloud_ptr,
135 cur_cloud_ptr_ = downsample_beams_cloud_ptr;
136 } else {
137 AWARN << "Down-sample beams factor must be >= 1. Cancel down-sampling."
138 " Current factor: "
140 }
141 }
142
143 // down sample the point cloud through filtering voxel grid
145 DownSampleOptions down_sample_options;
146 ACHECK(down_sample_ != nullptr);
147 down_sample_->Process(down_sample_options, cur_cloud_ptr_);
148 }
149 downsample_time_ = timer.toc(true);
150
151 num_points = cur_cloud_ptr_->size();
152 AINFO << "num points before fusing: " << num_points;
153
154 // fuse clouds of preceding frames with current cloud
155 cur_cloud_ptr_->mutable_points_timestamp()->assign(cur_cloud_ptr_->size(),
156 0.0);
157 if (param_.preprocess().enable_fuse_frames() &&
158 param_.preprocess().num_fuse_frames() > 1) {
159 // before fusing
160 while (!prev_world_clouds_.empty() &&
161 frame->timestamp - prev_world_clouds_.front()->get_timestamp() >
162 param_.preprocess().fuse_time_interval()) {
163 prev_world_clouds_.pop_front();
164 }
165 // transform current cloud to world coordinate and save to a new ptr
166 base::PointDCloudPtr cur_world_cloud_ptr =
167 std::make_shared<base::PointDCloud>();
168 for (size_t i = 0; i < cur_cloud_ptr_->size(); ++i) {
169 auto& pt = cur_cloud_ptr_->at(i);
170 Eigen::Vector3d trans_point(pt.x, pt.y, pt.z);
171 trans_point = lidar_frame_ref_->lidar2world_pose * trans_point;
172 PointD world_point;
173 world_point.x = trans_point(0);
174 world_point.y = trans_point(1);
175 world_point.z = trans_point(2);
176 world_point.intensity = pt.intensity;
177 cur_world_cloud_ptr->push_back(world_point);
178 }
179 cur_world_cloud_ptr->set_timestamp(frame->timestamp);
180
181 // fusing clouds
182 for (auto& prev_world_cloud_ptr : prev_world_clouds_) {
183 num_points += prev_world_cloud_ptr->size();
184 }
185 FuseCloud(cur_cloud_ptr_, prev_world_clouds_);
186
187 // after fusing
188 while (static_cast<int>(prev_world_clouds_.size()) >=
189 param_.preprocess().num_fuse_frames() - 1) {
190 prev_world_clouds_.pop_front();
191 }
192 prev_world_clouds_.emplace_back(cur_world_cloud_ptr);
193 }
194 AINFO << "num points after fusing: " << num_points;
195 fuse_time_ = timer.toc(true);
196
197 // shuffle points and cut off
198 if (param_.preprocess().enable_shuffle_points()) {
199 num_points = std::min(num_points, param_.preprocess().max_num_points());
200 std::vector<int> point_indices = GenerateIndices(0, num_points, true);
201 base::PointFCloudPtr shuffle_cloud_ptr(
202 new base::PointFCloud(*cur_cloud_ptr_, point_indices));
203 cur_cloud_ptr_ = shuffle_cloud_ptr;
204 }
205 shuffle_time_ = timer.toc(true);
206
207 // point cloud to array
208 float* points_array =
209 new float[num_points * param_.preprocess().num_point_feature()]();
210 CloudToArray(cur_cloud_ptr_, points_array,
211 param_.preprocess().normalizing_factor());
212 cloud_to_array_time_ = timer.toc(true);
213
214 // inference
215 std::vector<float> out_detections;
216 std::vector<int> out_labels;
217 point_pillars_ptr_->DoInference(points_array, num_points, &out_detections,
218 &out_labels);
219 inference_time_ = timer.toc(true);
220
221 // transfer output bounding boxes to objects
222 GetObjects(&frame->segmented_objects, frame->lidar2world_pose,
223 &out_detections, &out_labels);
224 collect_time_ = timer.toc(true);
225
226 AINFO << "PointPillars: "
227 << "\n"
228 << "down sample: " << downsample_time_ << "\t"
229 << "fuse: " << fuse_time_ << "\t"
230 << "shuffle: " << shuffle_time_ << "\t"
231 << "cloud_to_array: " << cloud_to_array_time_ << "\t"
232 << "inference: " << inference_time_ << "\t"
233 << "collect: " << collect_time_;
234
235 delete[] points_array;
236 return true;
237}
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
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
Point< double > PointD
Definition point.h:57
std::vector< std::shared_ptr< base::Object > > segmented_objects
Definition lidar_frame.h:53
optional common::PointCloudPreProcess preprocess

◆ Init()

bool apollo::perception::lidar::MaskPillarsDetection::Init ( const LidarDetectorInitOptions &  options = LidarDetectorInitOptions())
overridevirtual

Init of Mask Pillars Detection object

参数
optionslidar detection init options
返回
true
false

实现了 apollo::perception::lidar::BaseLidarDetector.

在文件 mask_pillars_detection.cc 第 50 行定义.

50 {
51 std::string config_file =
52 GetConfigFile(options.config_path, options.config_file);
54
55 const auto &model_info = param_.info();
56 std::string model_path = GetModelPath(model_info.name());
57 std::string weight_file =
58 GetModelFile(model_path, model_info.weight_file().file());
59
60 point_pillars_ptr_.reset(
61 new PointPillars(param_.preprocess().reproduce_result_mode(),
64 model_info.framework(),
65 weight_file));
66 if (param_.preprocess().enable_ground_removal()) {
67 z_min_ = std::max(z_min_,
68 static_cast<float>(
70 }
71
72 if (param_.has_plugins()) {
73 const auto &plugin = param_.plugins();
74 const auto &name = plugin.name();
76 ->CreateInstance<BaseDownSample>(
78 if (!down_sample_) {
79 AINFO << "Failed to find down_sample plugin: " << name << ", skipped";
80 return false;
81 }
82 DownSampleInitOptions option;
83 option.config_path = plugin.config_path();
84 option.config_file = plugin.config_file();
85 if (!down_sample_->Init(option)) {
86 AINFO << "Failed to init down_sample plugin: " << name << ", skipped";
87 return false;
88 }
89 }
90
91 return true;
92}
static PluginManager * Instance()
get singleton instance of PluginManager
std::shared_ptr< Base > CreateInstance(const std::string &derived_class)
create plugin instance of derived class based on Base
static std::string GetFullClassName(const std::string &class_name)
Given the class name of perception module, combine the namespace "apollo::perception::lidar::" with i...
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
std::string GetModelFile(const std::string &model_name, const std::string &file_name)
Get the model file path by model path and file name
Definition util.cc:55
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80
std::string GetModelPath(const std::string &model_name)
Get the model path by model name, search from APOLLO_MODEL_PATH
Definition util.cc:44
optional common::PointCloudPostProcess postprocess

◆ Name()

std::string apollo::perception::lidar::MaskPillarsDetection::Name ( ) const
inlineoverridevirtual

Name of Mask Pillars Detection module

返回
std::string

实现了 apollo::perception::lidar::BaseLidarDetector.

在文件 mask_pillars_detection.h 第 77 行定义.

77{ return "MaskPillarsDetection"; }

该类的文档由以下文件生成: