Apollo 11.0
自动驾驶开放平台
semantic_builder.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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
18
19namespace apollo {
20namespace perception {
21namespace lidar {
22
24 return true;
25}
26
28 if (frame == nullptr) {
29 return false;
30 }
31 std::vector<ObjectPtr>* objects = &(frame->segmented_objects);
32 for (size_t i = 0; i < objects->size(); ++i) {
33 if (objects->at(i)) {
34 GetObjSemanticAndMotionType(objects->at(i));
35 }
36 }
37 return true;
38}
39
40void SemanticBuilder::GetObjSemanticAndMotionType(ObjectPtr object) {
41 std::vector<int> type_count(static_cast<int>(PointSemanticLabel::MAX_LABEL), 0);
42 std::vector<int> motion_type_count(static_cast<int>(PointMotionLabel::MAX_LABEL), 0);
43 for (size_t i = 0; i < object->lidar_supplement.cloud.size(); i++) {
44 uint8_t value = object->lidar_supplement.cloud.points_semantic_label(i);
45 // get semantic label
47 int index = static_cast<int>(label);
48 if (index >= 0 && index < static_cast<int>(PointSemanticLabel::MAX_LABEL)) {
49 type_count[index]++;
50 }
51 // get motion label
52 PointMotionLabel motion_label = GetMotionLabel(value);
53 int motion_index = static_cast<int>(motion_label);
54 if (motion_index >= 0 && motion_index < static_cast<int>(PointMotionLabel::MAX_LABEL)) {
55 motion_type_count[motion_index]++;
56 }
57 }
58 // get sematic type
59 int max_value = -1;
60 int max_index = 0;
61 for (size_t i = 0; i < type_count.size(); i++) {
62 if (type_count.at(i) > max_value) {
63 max_value = type_count.at(i);
64 max_index = i;
65 }
66 }
67 // get object semantic type
68 object->lidar_supplement.semantic_type = static_cast<base::ObjectSemanticType>(max_index);
69
70 // get motion type
71 int motion_max_value = -1;
72 int motion_max_index = 0;
73 for (size_t i = 0; i < motion_type_count.size(); i++) {
74 if (motion_type_count.at(i) > motion_max_value) {
75 motion_max_value = motion_type_count.at(i);
76 motion_max_index = i;
77 }
78 }
79 // get object motion type
80 object->lidar_supplement.dynamic_state = static_cast<base::MotionState>(motion_max_index);
81}
82
83} // namespace lidar
84} // namespace perception
85} // namespace apollo
bool Init(const SemanticBuilderInitOptions &options=SemanticBuilderInitOptions())
Init the Semantic Builder with initialization options
bool Build(const SemanticBuilderOptions &options, LidarFrame *frame)
Get object semantic type.
PointSemanticLabel GetSemanticLabel(uint8_t value)
PointMotionLabel GetMotionLabel(uint8_t value)
std::shared_ptr< apollo::perception::base::Object > ObjectPtr
class register implement
Definition arena_queue.h:37
std::vector< std::shared_ptr< base::Object > > segmented_objects
Definition lidar_frame.h:53