Apollo  6.0
Open source self driving car software
base_feature_extractor.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 
26 
27 namespace apollo {
28 namespace perception {
29 namespace camera {
30 
31 // @brief: feature_extractor init options for each detected object
32 // @param [input_width/input_height]: input image width/height. required
33 // @param [feat_width/height/channel]: feat blob width/height/channel. required
34 // @param [max_object]: maximum num of objs for feature extractor. optional
35 // @param [param]: feature
37  int input_width = 0;
38  int input_height = 0;
39  std::shared_ptr<base::Blob<float>> feat_blob;
40  int gpu_id = 0;
41 };
42 
44  bool normalized = true;
45 };
47  public:
48  BaseFeatureExtractor() = default;
49  virtual ~BaseFeatureExtractor() = default;
50  virtual bool Init(const FeatureExtractorInitOptions &init_options) = 0;
51  // @brief: extract feature for each detected object
52  // @param [in/out]: objects with bounding boxes and feature vector.
53  virtual bool Extract(const FeatureExtractorOptions &options,
54  CameraFrame *frame) = 0;
55  virtual std::string Name() const = 0;
56 
57  void set_roi(int x, int y, int w, int h) {
58  roi_x_ = x;
59  roi_y_ = y;
60  roi_w_ = w;
61  roi_h_ = h;
62  }
63 
64  void decode_bbox(std::vector<std::shared_ptr<base::Object>> *objects) {
65  for (auto obj : *objects) {
66  auto &xmin = obj->camera_supplement.box.xmin;
67  auto &ymin = obj->camera_supplement.box.ymin;
68  auto &xmax = obj->camera_supplement.box.xmax;
69  auto &ymax = obj->camera_supplement.box.ymax;
70  xmin = xmin * static_cast<float>(roi_w_) + static_cast<float>(roi_x_);
71  xmax = xmax * static_cast<float>(roi_w_) + static_cast<float>(roi_x_);
72  ymin = ymin * static_cast<float>(roi_h_) + static_cast<float>(roi_y_);
73  ymax = ymax * static_cast<float>(roi_h_) + static_cast<float>(roi_y_);
74  }
75  }
76 
77  void encode_bbox(std::vector<std::shared_ptr<base::Object>> *objects) {
78  for (auto obj : *objects) {
79  auto &xmin = obj->camera_supplement.box.xmin;
80  auto &ymin = obj->camera_supplement.box.ymin;
81  auto &xmax = obj->camera_supplement.box.xmax;
82  auto &ymax = obj->camera_supplement.box.ymax;
83  xmin = (xmin - static_cast<float>(roi_x_)) / static_cast<float>(roi_w_);
84  xmax = (xmax - static_cast<float>(roi_x_)) / static_cast<float>(roi_w_);
85  ymin = (ymin - static_cast<float>(roi_y_)) / static_cast<float>(roi_h_);
86  ymax = (ymax - static_cast<float>(roi_y_)) / static_cast<float>(roi_h_);
87  }
88  }
89 
90  protected:
91  std::shared_ptr<base::Blob<float>> feat_blob_ = nullptr;
92  int roi_x_ = 0;
93  int roi_y_ = 0;
94  int roi_w_ = 0;
95  int roi_h_ = 0;
96 };
98 #define REGISTER_FEATURE_EXTRACTOR(name) \
99  PERCEPTION_REGISTER_CLASS(BaseFeatureExtractor, name)
100 
101 } // namespace camera
102 } // namespace perception
103 } // namespace apollo
PERCEPTION_REGISTER_REGISTERER(BaseCalibrationService)
Definition: base_init_options.h:24
Definition: camera_frame.h:33
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
int input_width
Definition: base_feature_extractor.h:37
int input_height
Definition: base_feature_extractor.h:38
void set_roi(int x, int y, int w, int h)
Definition: base_feature_extractor.h:57
void decode_bbox(std::vector< std::shared_ptr< base::Object >> *objects)
Definition: base_feature_extractor.h:64
Definition: base_feature_extractor.h:43
std::shared_ptr< base::Blob< float > > feat_blob
Definition: base_feature_extractor.h:39
bool Init(const char *binary_name)
int gpu_id
Definition: base_feature_extractor.h:40
Definition: base_feature_extractor.h:46
void encode_bbox(std::vector< std::shared_ptr< base::Object >> *objects)
Definition: base_feature_extractor.h:77
Definition: base_feature_extractor.h:36