Apollo 11.0
自动驾驶开放平台
spp_engine.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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
21
22namespace apollo {
23namespace perception {
24namespace lidar {
25
26void SppEngine::Init(size_t width, size_t height, float range,
27 const SppParams& param, const std::string& sensor_name) {
28 // initialize connect component detector
29 detector_2d_cc_.Init(static_cast<int>(height), static_cast<int>(width));
30 detector_2d_cc_.SetData(data_.obs_prob_data_ref, data_.offset_data,
31 static_cast<float>(height) / (2.f * range),
33 // initialize label image
34 labels_2d_.Init(width, height, sensor_name);
35 labels_2d_.InitRangeMask(range, param.confidence_range);
36 // set parameters of dynamic map
37 params_ = param;
38
39 // initialize feature size
40 width_ = width;
41 height_ = height;
42 range_ = range;
43 // bind worker
44 worker_.Bind([&]() {
48 data_.height_pt_blob->cpu_data();
49 return true;
50 });
51 worker_.Start();
52}
53
54size_t SppEngine::ProcessConnectedComponentCluster(
55 const base::PointFCloudConstPtr point_cloud, const CloudMask& mask) {
56 Timer timer;
59 double sync_time1 = timer.toc(true);
60 worker_.WakeUp();
61 size_t num = detector_2d_cc_.Detect(&labels_2d_);
62 if (num == 0) {
63 ADEBUG << "No object detected";
64 // Later will decide if return this function here
65 }
66 double detect_time = timer.toc(true);
67 worker_.Join();
68 double sync_time2 = timer.toc(true);
69 // labels_2d_.FilterClusters(data.confidence_data,
70 // data.confidence_threshold);
71 // 2018.6.21 filter use category data to reserve long range objects
72 // should be reverted after retrain model
73 labels_2d_.FilterClusters(data_.confidence_data, data_.obs_prob_data_ref[0],
76 double filter_time = timer.toc(true);
77 if (data_.class_prob_data != nullptr) {
78 labels_2d_.CalculateClusterClass(data_.class_prob_data, data_.class_num);
79 }
80 if (data_.heading_data != nullptr) {
81 labels_2d_.CalculateClusterHeading(data_.heading_data);
82 }
83 if (data_.z_data != nullptr) {
84 labels_2d_.CalculateClusterTopZ(data_.z_data);
85 }
86
87 double chz_time = timer.toc(true);
88 // 2. process 2d to 3d
89 // first sync between cluster list and label image,
90 // and they shared the same cluster pointer
91 clusters_ = labels_2d_;
92 for (size_t i = 0; i < point_cloud->size(); ++i) {
93 if (mask.size() && mask[static_cast<int>(i)] == 0) {
94 continue;
95 }
96 // out of range
97 const int id = data_.grid_indices[i];
98 if (id < 0) {
99 continue;
100 }
101 const auto& point = point_cloud->at(i);
102 const uint16_t& label = labels_2d_[0][id];
103 if (!label) {
104 continue;
105 }
106 if (point.z <=
107 labels_2d_.GetCluster(label - 1)->top_z + data_.top_z_threshold) {
108 clusters_.AddPointSample(label - 1, point, point_cloud->points_height(i),
109 static_cast<uint32_t>(i));
110 }
111 }
112 double mapping_time = timer.toc(true);
113 // 5. remove empty clusters
114 clusters_.RemoveEmptyClusters();
115 double remove_time = timer.toc(true);
116
117 AINFO << "SegForeground: sync1 " << sync_time1 << "\tdetect: " << detect_time
118 << "\tsync2: " << sync_time2 << "\tfilter: " << filter_time
119 << "\tchz: " << chz_time << "\tmapping: " << mapping_time
120 << "\tremove: " << remove_time;
121
122 return clusters_.size();
123}
124
126 const base::PointFCloudConstPtr point_cloud) {
127 mask_.clear();
128 ProcessConnectedComponentCluster(point_cloud, mask_);
129 AINFO << "Foreground: " << clusters_.size() << " clusters";
130 return clusters_.size();
131}
132
134 const base::PointFCloudConstPtr full_point_cloud,
135 const base::PointIndices& roi_indices,
136 const base::PointIndices& roi_non_ground_indices) {
137 mask_.Set(full_point_cloud->size(), 0);
138 mask_.AddIndices(roi_indices);
139 mask_.RemoveIndicesOfIndices(roi_indices, roi_non_ground_indices);
140 mask_.Flip();
141 // at this time, all ground points has mask value 0
142 for (size_t i = 0; i < clusters_.size(); ++i) {
143 clusters_[static_cast<int>(i)]->RemovePoints(mask_);
144 }
145 clusters_.RemoveEmptyClusters();
146 return clusters_.size();
147}
148
149} // namespace lidar
150} // namespace perception
151} // namespace apollo
const Dtype * cpu_data() const
Definition blob.cc:137
void Bind(const std::function< bool()> &func)
void AddIndices(const base::PointIndices &indices, int value=1)
Definition cloud_mask.cc:66
void Set(size_t size, int init_value)
Definition cloud_mask.h:34
void RemoveIndicesOfIndices(const base::PointIndices &indices, const base::PointIndices &indices_of_indices)
Definition cloud_mask.cc:82
void SetData(const float *const *prob_map, const float *offset_map, float scale, float objectness_threshold)
size_t Detect(SppLabelImage *labels)
void AddPointSample(size_t cluster_id, const base::PointF &point, float height, uint32_t point_id)
void Init(size_t width, size_t height, float range, const SppParams &param=SppParams(), const std::string &sensor_name="velodyne64")
Definition spp_engine.cc:26
size_t RemoveGroundPointsInForegroundCluster(const base::PointFCloudConstPtr full_point_cloud, const base::PointIndices &roi_indices, const base::PointIndices &roi_non_ground_indices)
size_t ProcessForegroundSegmentation(const base::PointFCloudConstPtr point_cloud)
void CalculateClusterTopZ(const float *top_z_map)
void CalculateClusterClass(const float *class_map, size_t class_num)
void CalculateClusterHeading(const float *heading_map)
void Init(size_t width, size_t height, const std::string &sensor_name="velodyne64")
void FilterClusters(const float *confidence_map, float threshold)
void InitRangeMask(float range, float boundary_distance)
double toc(bool reset=false)
Definition lidar_timer.h:28
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42
std::shared_ptr< const PointFCloud > PointFCloudConstPtr
class register implement
Definition arena_queue.h:37
base::Blob< float > * category_pt_blob
Definition spp_struct.h:33
base::Blob< float > * instance_pt_blob
Definition spp_struct.h:32
base::Blob< float > * heading_pt_blob
Definition spp_struct.h:36
base::Blob< float > * classify_pt_blob
Definition spp_struct.h:35
base::Blob< float > * height_pt_blob
Definition spp_struct.h:37
base::Blob< float > * confidence_pt_blob
Definition spp_struct.h:34