Apollo 9.0
自动驾驶开放平台
traffic_light_recognition_component.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 "cyber/time/clock.h"
22#include "modules/perception/traffic_light_recognition/proto/traffic_light_recognition_component.pb.h"
23
24namespace apollo {
25namespace perception {
26namespace trafficlight {
27
29 // init component config
30 if (InitConfig() != cyber::SUCC) {
31 AERROR << "TrafficLightRecognComponent InitConfig failed.";
32 return false;
33 }
34 // init algorithm plugin
35 if (InitAlgorithmPlugin() != cyber::SUCC) {
36 AERROR << "TrafficLightRecognComponent InitAlgorithmPlugin failed.";
37 return false;
38 }
39 AINFO << "Successfully init traffic light recognition component.";
40 return true;
41}
42
44 const std::shared_ptr<TrafficDetectMessage>& message) {
46 auto time_imags = std::to_string(message->timestamp_);
47 AINFO << "Enter recognition component, message timestamp: " << time_imags;
48
49 bool status = InternalProc(message);
50 if (status) {
51 writer_->Write(message);
52 AINFO << "Send trafficlight recognition output message.";
53 }
54 return status;
55}
56
57int TrafficLightRecognComponent::InitConfig() {
59 if (!GetProtoConfig(&traffic_light_param)) {
60 AINFO << "load trafficlights recognition component proto param failed";
61 return cyber::FAIL;
62 }
63
64 PluginParam plugin_param = traffic_light_param.plugin_param();
65 tl_recognitor_name_ = plugin_param.name();
66 config_path_ = plugin_param.config_path();
67 config_file_ = plugin_param.config_file();
68
69 gpu_id_ = traffic_light_param.gpu_id();
70 AINFO << "tl_recognitor_name: " << tl_recognitor_name_
71 << " config_path: " << config_path_ << " config_file: " << config_file_
72 << " gpu_id: " << gpu_id_;
73
74 writer_ = node_->CreateWriter<TrafficDetectMessage>(
75 traffic_light_param.recognition_output_channel_name());
76
77 return cyber::SUCC;
78}
79
80bool TrafficLightRecognComponent::InitAlgorithmPlugin() {
81 trafficlight::BaseTrafficLightRecognitor* recognitor =
82 trafficlight::BaseTrafficLightRecognitorRegisterer::GetInstanceByName(
83 tl_recognitor_name_);
84 CHECK_NOTNULL(recognitor);
85 recognitor_.reset(recognitor);
86 ACHECK(recognitor_ != nullptr);
87 recognitor_init_options_.gpu_id = gpu_id_;
88 recognitor_init_options_.config_path = config_path_;
89 recognitor_init_options_.config_file = config_file_;
90
91 if (!recognitor_->Init(recognitor_init_options_)) {
92 AERROR << "Trafficlight recognitor init failed";
93 return false;
94 }
95
96 return cyber::SUCC;
97}
98
99bool TrafficLightRecognComponent::InternalProc(
100 const std::shared_ptr<TrafficDetectMessage const>& message) {
101 PERF_BLOCK("traffic_light_recognition")
102 bool status = recognitor_->Detect(message->traffic_light_frame_.get());
104
105 return true;
106}
107
108} // namespace trafficlight
109} // namespace perception
110} // namespace apollo
bool GetProtoConfig(T *config) const
std::shared_ptr< Node > node_
bool Proc(const std::shared_ptr< TrafficDetectMessage > &message) override
Trigger the recognition process based on the traffic detect message.
bool Init() override
Initialize configuration files, algorithm plug-ins.
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
#define PERF_FUNCTION(...)
Definition profiler.h:54
#define PERF_BLOCK_END
Definition profiler.h:53
#define PERF_BLOCK(...)
Definition profiler.h:52