Apollo 11.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
43bool TrafficLightRecognComponent::Proc(const std::shared_ptr<TrafficDetectMessage>& message) {
45 auto time_imags = std::to_string(message->timestamp_);
46 AINFO << "Enter recognition component, message timestamp: " << time_imags;
47
48 bool status = InternalProc(message);
49 if (status) {
50 writer_->Write(message);
51 AINFO << "Send trafficlight recognition output message.";
52 }
53 return status;
54}
55
56int TrafficLightRecognComponent::InitConfig() {
58 if (!GetProtoConfig(&traffic_light_param)) {
59 AINFO << "load trafficlights recognition component proto param failed";
60 return cyber::FAIL;
61 }
62
63 PluginParam plugin_param = traffic_light_param.plugin_param();
64 tl_recognitor_name_ = plugin_param.name();
65 config_path_ = plugin_param.config_path();
66 config_file_ = plugin_param.config_file();
67
68 gpu_id_ = traffic_light_param.gpu_id();
69 AINFO << "tl_recognitor_name: " << tl_recognitor_name_ << " config_path: " << config_path_
70 << " config_file: " << config_file_ << " gpu_id: " << gpu_id_;
71
72 writer_ = node_->CreateWriter<TrafficDetectMessage>(traffic_light_param.recognition_output_channel_name());
73
74 return cyber::SUCC;
75}
76
77bool TrafficLightRecognComponent::InitAlgorithmPlugin() {
78 trafficlight::BaseTrafficLightRecognitor* recognitor
79 = trafficlight::BaseTrafficLightRecognitorRegisterer::GetInstanceByName(tl_recognitor_name_);
80 CHECK_NOTNULL(recognitor);
81 recognitor_.reset(recognitor);
82 ACHECK(recognitor_ != nullptr);
83 recognitor_init_options_.gpu_id = gpu_id_;
84 recognitor_init_options_.config_path = config_path_;
85 recognitor_init_options_.config_file = config_file_;
86
87 if (!recognitor_->Init(recognitor_init_options_)) {
88 AERROR << "Trafficlight recognitor init failed";
89 return false;
90 }
91
92 return cyber::SUCC;
93}
94
95bool TrafficLightRecognComponent::InternalProc(const std::shared_ptr<TrafficDetectMessage const>& message) {
96 PERF_BLOCK("traffic_light_recognition")
97 bool status = recognitor_->Detect(message->traffic_light_frame_.get());
99
100 return true;
101}
102
103} // namespace trafficlight
104} // namespace perception
105} // 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
Definition arena_queue.h:37
#define PERF_FUNCTION(...)
Definition profiler.h:54
#define PERF_BLOCK_END
Definition profiler.h:53
#define PERF_BLOCK(...)
Definition profiler.h:52