Apollo  6.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 
29 
34 
35 namespace apollo {
36 namespace perception {
37 namespace camera {
38 
40  public:
41  TLPreprocessor() = default;
42  ~TLPreprocessor() = default;
43 
44  bool Init(const TrafficLightPreprocessorInitOptions& options) override;
45 
46  std::string Name() const override;
47 
48  bool UpdateCameraSelection(const CarPose& pose,
49  const TLPreprocessorOption& option,
50  std::vector<base::TrafficLightPtr>* lights) override;
51 
52  bool SyncInformation(const double ts, const std::string& camera_name);
53  bool UpdateLightsProjection(const CarPose& pose,
54  const TLPreprocessorOption& option,
55  const std::string& camera_name,
56  std::vector<base::TrafficLightPtr>* lights) override;
57 
58  bool SetCameraWorkingFlag(const std::string& camera_name,
59  bool is_working) override;
60  bool GetCameraWorkingFlag(const std::string& camera_name,
61  bool* is_working) const override;
62 
63  const std::vector<std::string>&
65  return projection_.getCameraNamesByDescendingFocalLen();
66  }
67  bool GetAlllightsOutsideFlag() const;
68 
69  private:
70  void SelectCamera(
71  std::vector<base::TrafficLightPtrs>* lights_on_image_array,
72  std::vector<base::TrafficLightPtrs>* lights_outside_image_array,
73  const TLPreprocessorOption& option, std::string* selected_camera_name);
74 
75  // @brief Project lights from HDMap onto long focus or short focus image plane
76  bool ProjectLights(const CarPose& pose, const std::string& camera_name,
77  std::vector<base::TrafficLightPtr>* lights,
78  base::TrafficLightPtrs* lights_on_image,
79  base::TrafficLightPtrs* lights_outside_image);
80 
81  bool ProjectLightsAndSelectCamera(const CarPose& pose,
82  const TLPreprocessorOption& option,
83  std::string* selected_camera_name,
84  std::vector<base::TrafficLightPtr>* lights);
85 
86  std::string GetMinFocalLenWorkingCameraName() const;
87  std::string GetMaxFocalLenWorkingCameraName() const;
88 
89  private:
90  MultiCamerasProjection projection_;
91  double last_pub_img_ts_ = 0.0;
92 
93  // <timestamp, camera_name>
94  std::pair<double, std::string> selected_camera_name_;
95  std::map<std::string, bool> camera_is_working_flags_;
96  double sync_interval_seconds_ = 0.1; // some parameters from config file
97  size_t num_cameras_ = 0;
98  std::vector<base::TrafficLightPtrs> lights_on_image_array_;
99  std::vector<base::TrafficLightPtrs> lights_outside_image_array_;
100  base::TrafficLightPtrs lights_on_image_;
101  base::TrafficLightPtrs lights_outside_image_;
102  bool projections_outside_all_images_ = false;
103 };
104 
105 } // namespace camera
106 } // namespace perception
107 } // namespace apollo
bool GetCameraWorkingFlag(const std::string &camera_name, bool *is_working) const override
const std::vector< std::string > & GetCameraNamesByDescendingFocalLen() const override
Definition: tl_preprocessor.h:64
bool SyncInformation(const double ts, const std::string &camera_name)
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: base_tl_preprocessor.h:42
bool UpdateCameraSelection(const CarPose &pose, const TLPreprocessorOption &option, std::vector< base::TrafficLightPtr > *lights) override
Definition: multi_camera_projection.h:41
const std::vector< std::string > & getCameraNamesByDescendingFocalLen() const
Definition: multi_camera_projection.h:54
bool Init(const TrafficLightPreprocessorInitOptions &options) override
Definition: base_tl_preprocessor.h:38
bool SetCameraWorkingFlag(const std::string &camera_name, bool is_working) override
std::vector< TrafficLightPtr > TrafficLightPtrs
Definition: traffic_light.h:89
std::string Name() const override
Definition: tl_preprocessor.h:39
bool UpdateLightsProjection(const CarPose &pose, const TLPreprocessorOption &option, const std::string &camera_name, std::vector< base::TrafficLightPtr > *lights) override