Apollo 11.0
自动驾驶开放平台
recognition.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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
19#include "cyber/common/file.h"
21
22namespace apollo {
23namespace perception {
24namespace trafficlight {
25
27 std::string config_file = GetConfigFile(options.config_path, options.config_file);
28
29 if (!cyber::common::GetProtoFromFile(config_file, &recognize_param_)) {
30 AINFO << "load proto param failed, root dir: " << config_file;
31 return false;
32 }
33
34 classify_quadrate_.reset(new ClassifyBySimple);
35 classify_vertical_.reset(new ClassifyBySimple);
36 classify_horizontal_.reset(new ClassifyBySimple);
37
38 classify_quadrate_->Init(recognize_param_.quadrate_model(), options.gpu_id);
39 classify_vertical_->Init(recognize_param_.vertical_model(), options.gpu_id);
40 classify_horizontal_->Init(recognize_param_.horizontal_model(), options.gpu_id);
41
42 return true;
43}
44
46 std::vector<base::TrafficLightPtr> candidate(1);
47
48 for (base::TrafficLightPtr light : frame->traffic_lights) {
49 if (light->region.is_detected) {
50 candidate[0] = light;
51 if (light->region.detect_class_id == base::TLDetectionClass::TL_QUADRATE_CLASS) {
52 AINFO << "Recognize Use Quadrate Model!";
53 classify_quadrate_->Perform(frame, &candidate);
54 } else if (light->region.detect_class_id == base::TLDetectionClass::TL_VERTICAL_CLASS) {
55 AINFO << "Recognize Use Vertical Model!";
56 classify_vertical_->Perform(frame, &candidate);
57 } else if (light->region.detect_class_id == base::TLDetectionClass::TL_HORIZONTAL_CLASS) {
58 AINFO << "Recognize Use Horizonal Model!";
59 classify_horizontal_->Perform(frame, &candidate);
60 } else {
61 return false;
62 }
63 } else {
64 light->status.color = base::TLColor::TL_UNKNOWN_COLOR;
65 light->status.confidence = 0;
66 }
67 }
68
69 return true;
70}
71
73
74} // namespace trafficlight
75} // namespace perception
76} // namespace apollo
#define REGISTER_TRAFFIC_LIGHT_DETECTOR(name)
bool Detect(camera::TrafficLightFrame *frame) override
recogn traffic_light from image.
bool Init(const TrafficLightRecognitorInitOptions &options) override
Initialize traffic light recognitor parameters.
#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::shared_ptr< TrafficLight > TrafficLightPtr
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
std::vector< base::TrafficLightPtr > traffic_lights