Apollo 11.0
自动驾驶开放平台
radar_obstacle_perception.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 *****************************************************************************/
17
18#include "modules/perception/radar4d_detection/proto/radar_obstacle_perception_config.pb.h"
19
20#include "cyber/common/file.h"
21#include "cyber/common/log.h"
25
26namespace apollo {
27namespace perception {
28namespace radar4d {
29
31 // Init config
32 std::string config_file =
33 GetConfigFile(options.config_path, options.config_file);
34 RadarObstaclePerceptionConfig radar_obstacle_config;
35 if (!cyber::common::GetProtoFromFile(config_file, &radar_obstacle_config)) {
36 AERROR << "Read config failed: " << config_file;
37 return false;
38 }
39
40 // object detector
41 auto detector_param = radar_obstacle_config.detector_param();
42 DetectorInitOptions detector_init_options;
43 detector_init_options.config_path = detector_param.config_path();
44 detector_init_options.config_file = detector_param.config_file();
45 BaseDetector* detector =
46 BaseDetectorRegisterer::GetInstanceByName(detector_param.name());
47 CHECK_NOTNULL(detector);
48 detector_.reset(detector);
49 ACHECK(detector_->Init(detector_init_options)) << "radar detector init error";
50
51 // object builder
52 enable_roi_filter_ = radar_obstacle_config.enable_roi_filter();
53 ACHECK(builder_.Init(detector_init_options)) << "radar builder init error";
54
55 // hdmap roi filter
56 auto roi_filter_param = radar_obstacle_config.roi_filter_param();
57 RoiFilterInitOptions roi_filter_init_options;
58 roi_filter_init_options.config_path = roi_filter_param.config_path();
59 roi_filter_init_options.config_file = roi_filter_param.config_file();
60 BaseRoiFilter* roi_filter =
61 BaseRoiFilterRegisterer::GetInstanceByName(roi_filter_param.name());
62 CHECK_NOTNULL(roi_filter);
63 roi_filter_.reset(roi_filter);
64 ACHECK(roi_filter_->Init(roi_filter_init_options))
65 << "radar roi filter init error";
66
67 // multi target tracking init
68 auto multi_target_tracker_param =
69 radar_obstacle_config.multi_target_tracker_param();
70 multi_target_tracker_ = BaseMultiTargetTrackerRegisterer::GetInstanceByName(
71 multi_target_tracker_param.name());
72 CHECK_NOTNULL(multi_target_tracker_);
73
74 MultiTargetTrackerInitOptions tracker_init_options;
75 tracker_init_options.config_path = multi_target_tracker_param.config_path();
76 tracker_init_options.config_file = multi_target_tracker_param.config_file();
77 ACHECK(multi_target_tracker_->Init(tracker_init_options));
78
79 // fused classifier init
80 auto fusion_classifier_param =
81 radar_obstacle_config.fusion_classifier_param();
82 fusion_classifier_ = BaseClassifierRegisterer::GetInstanceByName(
83 fusion_classifier_param.name());
84 CHECK_NOTNULL(fusion_classifier_);
85
86 ClassifierInitOptions fusion_classifier_init_options;
87 fusion_classifier_init_options.config_path =
88 fusion_classifier_param.config_path();
89 fusion_classifier_init_options.config_file =
90 fusion_classifier_param.config_file();
91 ACHECK(fusion_classifier_->Init(fusion_classifier_init_options));
92 return true;
93}
94
96 RadarFrame* frame,
97 const RadarPerceptionOptions& options,
98 std::vector<base::ObjectPtr>* objects) {
100 const std::string& sensor_name = options.sensor_name;
102
103 // object detection
104 if (!detector_->Detect(frame, options.detector_options)) {
105 AERROR << "radar detect error";
106 return false;
107 }
108 // object builder
109 if (!builder_.Build(options.detector_options, frame)) {
110 AERROR << "radar detector, object builder error.";
111 return false;
112 }
113 AINFO << "Detected frame objects number: "
114 << frame->segmented_objects.size();
115 PERF_BLOCK_END_WITH_INDICATOR(sensor_name, "detector");
116
117 // roi filter
118 if (enable_roi_filter_) {
119 if (!roi_filter_->RoiFilter(options.roi_filter_options, frame)) {
120 AINFO << "All radar objects were filtered out";
121 }
122 AINFO << "RoiFiltered frame objects number: "
123 << frame->segmented_objects.size();
124 PERF_BLOCK_END_WITH_INDICATOR(sensor_name, "roi_filter");
125 }
126
127 // multi target tracker
128 MultiTargetTrackerOptions tracker_options;
129 if (!multi_target_tracker_->Track(tracker_options, frame)) {
130 AERROR << "radar4d tracking, multi_target_tracker_ Track error.";
131 return false;
132 }
133 PERF_BLOCK_END_WITH_INDICATOR(sensor_name, "tracker");
134
135 // fused classifer
136 // ClassifierOptions fusion_classifier_options;
137 // if (!fusion_classifier_->Classify(fusion_classifier_options,
138 // frame)) {
139 // AERROR << "radar4d tracking, fusion_classifier_ Classify error.";
140 // return false;
141 // }
142 // PERF_BLOCK_END_WITH_INDICATOR(sensor_name, "tracker");
143
144 *objects = frame->tracked_objects;
145
146 return true;
147}
148
149std::string RadarObstaclePerception::Name() const {
150 return "RadarObstaclePerception";
151}
152
154
155} // namespace radar4d
156} // namespace perception
157} // namespace apollo
#define PERCEPTION_REGISTER_RADAR_OBSTACLE_PERCEPTION(name)
virtual bool Init(const ClassifierInitOptions &options=ClassifierInitOptions())=0
Init classifier
virtual bool Track(const MultiTargetTrackerOptions &options, RadarFrame *frame)=0
Track segmented objects and estimate motion and shape
virtual bool Init(const MultiTargetTrackerInitOptions &options=MultiTargetTrackerInitOptions())=0
Init multi target tarcker
bool Init(const DetectorInitOptions &options=DetectorInitOptions())
Init the Object Builder object with initialization options
bool Build(const DetectorOptions &options, RadarFrame *frame)
Calculate and fill object size, center, directions.
bool Perceive(RadarFrame *frame, const RadarPerceptionOptions &options, std::vector< base::ObjectPtr > *objects) override
Process radar frame with preprocessed point cloud, and get targets after detection and tracking.
std::string Name() const override
The name of the radar object detection processor
bool Init(const PerceptionInitOptions &options) override
Init the radar object detection processor includes config, create classes, etc.
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
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 GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80
class register implement
Definition arena_queue.h:37
#define PERF_BLOCK_END_WITH_INDICATOR(indicator, msg)
Definition perf_util.h:128
#define PERF_BLOCK_START()
Definition perf_util.h:126
#define PERF_FUNCTION(...)
Definition profiler.h:54
std::vector< std::shared_ptr< base::Object > > tracked_objects
Definition radar_frame.h:49
std::vector< std::shared_ptr< base::Object > > segmented_objects
Definition radar_frame.h:47