Apollo 11.0
自动驾驶开放平台
base_feature_extractor.h
浏览该文件的文档.
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
27namespace apollo {
28namespace perception {
29namespace 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 std::string feature_path;
41 std::string feature_file;
42};
43
45 bool normalized = true;
46};
47
49 public:
51 virtual ~BaseFeatureExtractor() = default;
52 virtual bool Init(const FeatureExtractorInitOptions &init_options) = 0;
53 // @brief: extract feature for each detected object
54 // @param [in/out]: objects with bounding boxes and feature vector.
55 virtual bool Extract(const FeatureExtractorOptions &options,
57
58 void set_roi(int x, int y, int w, int h) {
59 roi_x_ = x;
60 roi_y_ = y;
61 roi_w_ = w;
62 roi_h_ = h;
63 }
64
65 void decode_bbox(std::vector<std::shared_ptr<base::Object>> *objects) {
66 for (auto obj : *objects) {
67 auto &xmin = obj->camera_supplement.box.xmin;
68 auto &ymin = obj->camera_supplement.box.ymin;
69 auto &xmax = obj->camera_supplement.box.xmax;
70 auto &ymax = obj->camera_supplement.box.ymax;
71 xmin = xmin * static_cast<float>(roi_w_) + static_cast<float>(roi_x_);
72 xmax = xmax * static_cast<float>(roi_w_) + static_cast<float>(roi_x_);
73 ymin = ymin * static_cast<float>(roi_h_) + static_cast<float>(roi_y_);
74 ymax = ymax * static_cast<float>(roi_h_) + static_cast<float>(roi_y_);
75 }
76 }
77
78 void encode_bbox(std::vector<std::shared_ptr<base::Object>> *objects) {
79 for (auto obj : *objects) {
80 auto &xmin = obj->camera_supplement.box.xmin;
81 auto &ymin = obj->camera_supplement.box.ymin;
82 auto &xmax = obj->camera_supplement.box.xmax;
83 auto &ymax = obj->camera_supplement.box.ymax;
84 xmin = (xmin - static_cast<float>(roi_x_)) / static_cast<float>(roi_w_);
85 xmax = (xmax - static_cast<float>(roi_x_)) / static_cast<float>(roi_w_);
86 ymin = (ymin - static_cast<float>(roi_y_)) / static_cast<float>(roi_h_);
87 ymax = (ymax - static_cast<float>(roi_y_)) / static_cast<float>(roi_h_);
88 }
89 }
90
91 protected:
92 std::shared_ptr<base::Blob<float>> feat_blob_ = nullptr;
93 int roi_x_ = 0;
94 int roi_y_ = 0;
95 int roi_w_ = 0;
96 int roi_h_ = 0;
97};
99#define REGISTER_FEATURE_EXTRACTOR(name) \
100 PERCEPTION_REGISTER_CLASS(BaseFeatureExtractor, name)
101
102} // namespace camera
103} // namespace perception
104} // namespace apollo
void encode_bbox(std::vector< std::shared_ptr< base::Object > > *objects)
virtual bool Init(const FeatureExtractorInitOptions &init_options)=0
std::shared_ptr< base::Blob< float > > feat_blob_
void decode_bbox(std::vector< std::shared_ptr< base::Object > > *objects)
virtual bool Extract(const FeatureExtractorOptions &options, camera::CameraTrackingFrame *frame)=0
class register implement
Definition arena_queue.h:37
#define PERCEPTION_REGISTER_REGISTERER(base_class)
Definition registerer.h:92