Apollo  6.0
Open source self driving car software
detection.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 <memory>
19 #include <string>
20 #include <vector>
21 
27 #include "modules/perception/camera/lib/traffic_light/proto/detection.pb.h"
29 
30 namespace apollo {
31 namespace perception {
32 namespace camera {
33 
35  public:
37  mean_[0] = 0;
38  mean_[1] = 0;
39  mean_[2] = 0;
40  }
41 
43 
44  bool Init(const TrafficLightDetectorInitOptions &options) override;
45 
46  // @brief: detect traffic_light from image.
47  // @param [in]: options
48  // @param [in/out]: frame
49  // traffic_light type and 2D bbox should be filled, required,
50  bool Detect(const TrafficLightDetectorOptions &options,
51  CameraFrame *frame) override;
52  bool SelectOutputBoxes(const std::vector<base::RectI> &crop_box_list,
53  const std::vector<float> &resize_scale_list_col,
54  const std::vector<float> &resize_scale_list_row,
55  std::vector<base::TrafficLightPtr> *lights);
56  void ApplyNMS(std::vector<base::TrafficLightPtr> *lights,
57  double iou_thresh = 0.6);
58  bool Inference(std::vector<base::TrafficLightPtr> *lights,
59  DataProvider *data_provider);
60  std::string Name() const override;
61  const std::vector<base::TrafficLightPtr> &getDetectedBoxes() {
62  return detected_bboxes_;
63  }
64 
67 
68  private:
69  traffic_light::detection::DetectionParam detection_param_;
70  DataProvider::ImageOptions data_provider_image_option_;
71  std::shared_ptr<inference::Inference> rt_net_ = nullptr;
72  std::shared_ptr<base::Image8U> image_ = nullptr;
73  std::shared_ptr<base::Blob<float>> param_blob_;
74  std::shared_ptr<base::Blob<float>> mean_buffer_;
75  std::shared_ptr<IGetBox> crop_;
76  std::vector<base::TrafficLightPtr> detected_bboxes_;
77  std::vector<base::TrafficLightPtr> selected_bboxes_;
78  std::vector<std::string> net_inputs_;
79  std::vector<std::string> net_outputs_;
80  Select select_;
81  int max_batch_size_ = 4;
82  int param_blob_length_ = 6;
83  float mean_[3];
84  std::vector<base::RectI> crop_box_list_;
85  std::vector<float> resize_scale_list_;
86  int gpu_id_ = 0;
87 }; // class TrafficLightDetection
88 
89 } // namespace camera
90 } // namespace perception
91 } // namespace apollo
Definition: data_provider.h:30
Definition: camera_frame.h:33
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool Detect(const TrafficLightDetectorOptions &options, CameraFrame *frame) override
Definition: base_traffic_light_detector.h:35
Definition: select.h:29
bool SelectOutputBoxes(const std::vector< base::RectI > &crop_box_list, const std::vector< float > &resize_scale_list_col, const std::vector< float > &resize_scale_list_row, std::vector< base::TrafficLightPtr > *lights)
TrafficLightDetection & operator=(const TrafficLightDetection &)=delete
Definition: base_traffic_light_detector.h:37
const std::vector< base::TrafficLightPtr > & getDetectedBoxes()
Definition: detection.h:61
bool Inference(std::vector< base::TrafficLightPtr > *lights, DataProvider *data_provider)
~TrafficLightDetection()
Definition: detection.h:42
Definition: base_traffic_light_detector.h:31
void ApplyNMS(std::vector< base::TrafficLightPtr > *lights, double iou_thresh=0.6)
bool Init(const TrafficLightDetectorInitOptions &options) override
TrafficLightDetection()
Definition: detection.h:36