104 if (frame ==
nullptr) {
105 AERROR <<
"Input null frame ptr.";
109 AERROR <<
"Input null frame cloud.";
113 AERROR <<
"Input none points.";
117 unsigned int data_id = 0;
118 unsigned int semantic_data_id = 0;
119 unsigned int valid_point_num = 0;
120 unsigned int valid_point_num_cur = 0;
122 size_t num_points = 0;
123 size_t num_points_all = 0;
125 unsigned int nr_points_element = 3;
146 num_points_all = num_points;
148 if (num_points_all > default_point_size_) {
149 default_point_size_ = num_points * 2;
150 point_attribute_.resize(default_point_size_);
151 point_indices_temp_.resize(default_point_size_);
152 data_.resize(default_point_size_ * 3);
153 semantic_data_.resize(default_point_size_);
154 ground_height_signed_.resize(default_point_size_);
160 size_t near_ground_count = 0;
161 float near_ground_z = 0.0;
163 for (i = 0; i < num_points; ++i) {
171 point_attribute_[i] = std::make_pair(index, valid_point_num);
172 point_indices_temp_[valid_point_num++] = index;
174 frame->
cloud->points_semantic_label(index));
175 if (single_ground_detect_) {
176 const auto& pt = frame->
cloud->at(index);
177 data_[data_id++] =
static_cast<float>(pt.x);
178 data_[data_id++] =
static_cast<float>(pt.y);
179 data_[data_id++] =
static_cast<float>(pt.z);
180 semantic_data_[semantic_data_id++] =
static_cast<int>(
183 fabs(pt.x) <= near_range_ && fabs(pt.y) <= near_range_) {
185 near_ground_z += pt.z;
189 data_[data_id++] =
static_cast<float>(pt.x - cloud_center_(0));
190 data_[data_id++] =
static_cast<float>(pt.y - cloud_center_(1));
191 data_[data_id++] =
static_cast<float>(pt.z - cloud_center_(2));
192 semantic_data_[semantic_data_id++] =
static_cast<int>(
195 fabs(pt.x - cloud_center_(0)) <= near_range_ &&
196 fabs(pt.y - cloud_center_(1)) <= near_range_) {
198 near_ground_z += pt.z;
203 for (i = 0; i < num_points; ++i) {
210 point_attribute_[i] = std::make_pair(i, valid_point_num);
211 point_indices_temp_[valid_point_num++] =
static_cast<int>(i);
213 frame->
cloud->points_semantic_label(i));
214 if (single_ground_detect_) {
215 const auto& pt = frame->
cloud->at(i);
216 data_[data_id++] =
static_cast<float>(pt.x);
217 data_[data_id++] =
static_cast<float>(pt.y);
218 data_[data_id++] =
static_cast<float>(pt.z);
219 semantic_data_[semantic_data_id++] =
static_cast<int>(
222 fabs(pt.x) <= near_range_ && fabs(pt.y) <= near_range_) {
224 near_ground_z += pt.z;
228 data_[data_id++] =
static_cast<float>(pt.x - cloud_center_(0));
229 data_[data_id++] =
static_cast<float>(pt.y - cloud_center_(1));
230 data_[data_id++] =
static_cast<float>(pt.z - cloud_center_(2));
231 semantic_data_[semantic_data_id++] =
static_cast<int>(
234 fabs(pt.x - cloud_center_(0)) <= near_range_ &&
235 fabs(pt.y - cloud_center_(1)) <= near_range_) {
237 near_ground_z += pt.z;
243 CHECK_GE(num_points, valid_point_num);
244 CHECK_EQ(data_id, valid_point_num * 3);
245 CHECK_EQ(semantic_data_id, valid_point_num);
248 AINFO <<
"spatial temporal seg: use roi " << use_roi_ <<
" roi points "
249 << num_points <<
" and input of ground detector: " << valid_point_num;
251 pfdetector_->
ResetParams(ori_sample_z_lower_, ori_sample_z_upper_);
252 if (use_semantic_ground_) {
253 if (near_ground_count > 0) {
254 pfdetector_->
UpdateParams(near_ground_z * 1.0f / near_ground_count,
255 parsing_height_buffer_, frame->
timestamp);
258 parsing_height_buffer_, frame->
timestamp);
261 if (!pfdetector_->
Detect(data_.data(), semantic_data_.data(),
262 ground_height_signed_.data(), valid_point_num, nr_points_element)) {
263 ADEBUG <<
"failed to call ground detector!";
264 non_ground_indices.
indices.insert(
265 non_ground_indices.
indices.end(), point_indices_temp_.begin(),
266 point_indices_temp_.begin() + valid_point_num);
286 size_t ground_z_value_count = 0;
287 float ground_z_value = 0.0;
288 if (origin_ground_z_array_.size() >= ground_z_average_frame) {
289 origin_ground_z_array_.pop_front();
291 auto valid_index = [&](
int row,
int col) {
292 if (row >= 0 && row < grid_size_ && col >= 0 && col < grid_size_) {
297 for (i = 0; i < num_points; ++i) {
300 size_t pc_index = point_attribute_[i].first;
301 size_t count = point_attribute_[i].second;
304 if (single_ground_detect_) {
305 const auto& pt = frame->
cloud->at(pc_index);
311 pc[0] = pt.x - cloud_center_(0);
312 pc[1] = pt.y - cloud_center_(1);
313 pc[2] = pt.z - cloud_center_(2);
318 int cur_row, cur_col = 0;
319 std::vector<std::pair<int, int>> neighbors;
320 pfdetector_->
Pc2Voxel(pc[0], pc[1], pc[2], &cur_row, &cur_col);
321 neighbors.push_back(std::make_pair(cur_row, cur_col));
322 neighbors.push_back(std::make_pair(cur_row - 1, cur_col));
323 neighbors.push_back(std::make_pair(cur_row + 1, cur_col));
324 neighbors.push_back(std::make_pair(cur_row, cur_col - 1));
325 neighbors.push_back(std::make_pair(cur_row, cur_col + 1));
326 float min_z = std::numeric_limits<float>::max();
327 for (
size_t k = 0; k < neighbors.size(); k++) {
328 int row = neighbors[k].first;
329 int col = neighbors[k].second;
330 if (!valid_index(row, col)) {
338 min_z = std::fabs(z_dis) < min_z ? std::fabs(z_dis) : min_z;
343 z_dis = ground_height_signed_.data()[count];
345 frame->
cloud->mutable_points_height()->at(pc_index) = z_dis;
346 frame->
world_cloud->mutable_points_height()->at(pc_index) = z_dis;
348 const auto& ppp = frame->
cloud->at(pc_index);
349 Eigen::Vector3d pc_novatel =
352 if (pc_novatel(1) > 0 && pc_novatel(1) < near_range_dist_ &&
353 pc_novatel(0) > FLAGS_x_back - 0.1 &&
354 pc_novatel(0) < FLAGS_x_front + 0.1) {
357 if (pc_novatel(1) >= near_range_dist_ &&
358 pc_novatel(1) < middle_range_dist_ &&
359 pc_novatel(0) > FLAGS_x_back - 0.1 &&
360 pc_novatel(0) < FLAGS_x_front + 0.1) {
366 non_ground_indices.
indices.push_back(i);
368 frame->
cloud->mutable_points_label()->at(pc_index) =
370 frame->
world_cloud->mutable_points_label()->at(pc_index) =
372 if (sqrt(ppp.x * ppp.x + ppp.y * ppp.y) < 8 && fabs(z_dis) < 0.1) {
373 ++ground_z_value_count;
374 ground_z_value += ppp.z;
378 AINFO <<
"succeed to call ground detector with non ground points "
379 << non_ground_indices.
indices.size();
381 float oriHeight = ground_z_value /
382 (
static_cast<float>(ground_z_value_count) * 1.0f);
383 origin_ground_z_array_.push_back(oriHeight);
384 float ori_height = 0.0;
385 for (
auto value : origin_ground_z_array_) {
389 (
static_cast<float>(origin_ground_z_array_.size()) * 1.0f);
395 out1.open(
"semantic/" + std::to_string(frame->
timestamp) +
".txt");
396 if (out1.is_open()) {
397 for (
size_t i = 0; i < frame->
cloud->size(); i++) {
399 frame->
cloud->points_semantic_label(i)));
401 frame->
cloud->points_semantic_label(i)));
402 int label_index =
static_cast<uint8_t
>(
403 frame->
cloud->points_label(i));
404 if (single_ground_detect_) {
405 const auto& pt = frame->
cloud->at(i);
406 out1 << pt.x <<
", " << pt.y <<
", " << pt.z <<
", "
407 << pt.intensity <<
", " << parsing_index <<
", "
408 << sbr_index <<
", " << label_index << std::endl;
411 out1 << pt.x - cloud_center_(0) <<
", "
412 << pt.y - cloud_center_(1) <<
", "
413 << pt.z - cloud_center_(2) <<
", " << pt.intensity
414 <<
", " << parsing_index <<
", " << sbr_index <<
", "
415 << label_index << std::endl;
422 if (use_ground_service_) {
424 if (ground_service !=
nullptr) {
430 unsigned int index = 0;
431 for (
unsigned int r = 0; r < rows; ++r) {
432 for (
unsigned int c = 0; c < cols; ++c) {
436 index = r * cols + c;
446 ground_service->UpdateServiceContent(ground_service_content_);
448 AINFO <<
"Failed to find ground service and cannot update.";