Apollo  v5.5.0
Open source self driving car software
tl_preprocessor.h
Go to the documentation of this file.
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 #pragma once
17 
18 #include <map>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 #include "boost/circular_buffer.hpp"
24 
31 
32 namespace apollo {
33 namespace perception {
34 namespace camera {
35 
37  int gpu_id = 0;
39  std::vector<std::string> camera_names;
40 };
41 
43  std::map<std::string, int>* image_borders_size = nullptr;
44 };
45 
47  public:
48  TLPreprocessor() = default;
49  ~TLPreprocessor() = default;
50 
51  bool Init(const TrafficLightPreprocessorInitOptions& options);
52 
53  std::string Name() const;
54 
55  bool UpdateCameraSelection(const CarPose& pose,
56  const TLPreprocessorOption& option,
57  std::vector<base::TrafficLightPtr>* lights);
58 
59  bool SyncInformation(const double ts, const std::string& camera_name);
60  bool UpdateLightsProjection(const CarPose& pose,
61  const TLPreprocessorOption& option,
62  const std::string& camera_name,
63  std::vector<base::TrafficLightPtr>* lights);
64 
65  bool SetCameraWorkingFlag(const std::string& camera_name, bool is_working);
66  bool GetCameraWorkingFlag(const std::string& camera_name,
67  bool* is_working) const;
68 
69  const std::vector<std::string>& GetCameraNamesByDescendingFocalLen() const {
70  return projection_.getCameraNamesByDescendingFocalLen();
71  }
72  bool GetAlllightsOutsideFlag() const;
73 
74  private:
75  void SelectCamera(
76  std::vector<base::TrafficLightPtrs>* lights_on_image_array,
77  std::vector<base::TrafficLightPtrs>* lights_outside_image_array,
78  const TLPreprocessorOption& option, std::string* selected_camera_name);
79 
80  // @brief Project lights from HDMap onto long focus or short focus image plane
81  bool ProjectLights(const CarPose& pose, const std::string& camera_name,
82  std::vector<base::TrafficLightPtr>* lights,
83  base::TrafficLightPtrs* lights_on_image,
84  base::TrafficLightPtrs* lights_outside_image);
85 
86  bool ProjectLightsAndSelectCamera(const CarPose& pose,
87  const TLPreprocessorOption& option,
88  std::string* selected_camera_name,
89  std::vector<base::TrafficLightPtr>* lights);
90 
91  std::string GetMinFocalLenWorkingCameraName() const;
92  std::string GetMaxFocalLenWorkingCameraName() const;
93 
94  private:
95  MultiCamerasProjection projection_;
96  double last_pub_img_ts_ = 0.0;
97 
98  // <timestamp, camera_name>
99  std::pair<double, std::string> selected_camera_name_;
100  std::map<std::string, bool> camera_is_working_flags_;
101  double sync_interval_seconds_ = 0.1; // some parameters from config file
102  size_t num_cameras_ = 0;
103  std::vector<base::TrafficLightPtrs> lights_on_image_array_;
104  std::vector<base::TrafficLightPtrs> lights_outside_image_array_;
105  base::TrafficLightPtrs lights_on_image_;
106  base::TrafficLightPtrs lights_outside_image_;
107  bool projections_outside_all_images_ = false;
108 };
109 
110 } // namespace camera
111 } // namespace perception
112 } // namespace apollo
Definition: base_init_options.h:24
const std::vector< std::string > & GetCameraNamesByDescendingFocalLen() const
Definition: tl_preprocessor.h:69
Definition: blob.h:72
float sync_interval_seconds
Definition: tl_preprocessor.h:38
Definition: multi_camera_projection.h:41
Definition: tl_preprocessor.h:42
std::vector< TrafficLightPtr > TrafficLightPtrs
Definition: traffic_light.h:89
Definition: tl_preprocessor.h:46
std::vector< std::string > camera_names
Definition: tl_preprocessor.h:39