Apollo 10.0
自动驾驶开放平台
apollo::perception::camera::SmokeObstacleDetector类 参考

#include <smoke_obstacle_detector.h>

类 apollo::perception::camera::SmokeObstacleDetector 继承关系图:
apollo::perception::camera::SmokeObstacleDetector 的协作图:

Public 成员函数

 SmokeObstacleDetector ()=default
 
virtual ~SmokeObstacleDetector ()=default
 
bool Init (const ObstacleDetectorInitOptions &options) override
 Init function for SmokeObstacleDetector
 
bool Detect (onboard::CameraFrame *frame) override
 Main part to detect obstacle
 
std::string Name () const override
 Interface for obstacle detector name
 
- Public 成员函数 继承自 apollo::perception::camera::BaseObstacleDetector
 BaseObstacleDetector ()=default
 
virtual ~BaseObstacleDetector ()=default
 
virtual bool Detect (CameraFrame *frame)=0
 Interface for obstacle detector main part
 
virtual bool InitNetwork (const common::ModelInfo &model_info, const std::string &model_root)
 Interface for network initialization
 
 BaseObstacleDetector ()=default
 
virtual ~BaseObstacleDetector ()=default
 
virtual bool Detect (CameraFrame *frame)=0
 Interface for obstacle detector main part
 
virtual bool InitNetwork (const common::ModelInfo &model_info, const std::string &model_root)
 Interface for network initialization
 
 BaseObstacleDetector ()=default
 
virtual ~BaseObstacleDetector ()=default
 
virtual bool InitNetwork (const common::ModelInfo &model_info, const std::string &model_root)
 Interface for network initialization
 

Protected 成员函数

void InitImageOffset (const smoke::ModelParam &model_param)
 
void InitImageSize (const smoke::ModelParam &model_param)
 
void InitParam (const smoke::ModelParam &model_param)
 
void InitObstacleTypes ()
 
bool Preprocess (const base::Image8U *image, std::shared_ptr< base::Blob< float > > input_blob)
 
- Protected 成员函数 继承自 apollo::perception::camera::BaseObstacleDetector
 DISALLOW_COPY_AND_ASSIGN (BaseObstacleDetector)
 
 DISALLOW_COPY_AND_ASSIGN (BaseObstacleDetector)
 
 DISALLOW_COPY_AND_ASSIGN (BaseObstacleDetector)
 

额外继承的成员函数

- Protected 属性 继承自 apollo::perception::camera::BaseObstacleDetector
int gpu_id_ = 0
 
std::shared_ptr< inference::Inferencenet_
 

详细描述

在文件 smoke_obstacle_detector.h34 行定义.

构造及析构函数说明

◆ SmokeObstacleDetector()

apollo::perception::camera::SmokeObstacleDetector::SmokeObstacleDetector ( )
default

◆ ~SmokeObstacleDetector()

virtual apollo::perception::camera::SmokeObstacleDetector::~SmokeObstacleDetector ( )
virtualdefault

成员函数说明

◆ Detect()

bool apollo::perception::camera::SmokeObstacleDetector::Detect ( onboard::CameraFrame frame)
overridevirtual

Main part to detect obstacle

参数
frame
返回
true
false

实现了 apollo::perception::camera::BaseObstacleDetector.

在文件 smoke_obstacle_detector.cc143 行定义.

143 {
144 if (frame == nullptr) {
145 return false;
146 }
147
148 if (cudaSetDevice(options_.gpu_id) != cudaSuccess) {
149 AERROR << "Failed to set device to " << options_.gpu_id;
150 return false;
151 }
152
153 // Check init height == runtime height
154 if (options_.image_height != frame->data_provider->src_height() ||
155 options_.image_width != frame->data_provider->src_width()) {
156 AWARN << "Initialized image size not equal to runtime!";
157 }
158
159 auto model_inputs = model_param_.info().inputs();
160 auto input_blob = net_->get_blob(model_inputs[0].name());
161 auto input_k_blob = net_->get_blob(model_inputs[1].name());
162 auto input_ratio_blob = net_->get_blob(model_inputs[2].name());
163
164 // Input k matrix
165 const auto &camera_k_matrix = options_.intrinsic.inverse();
166 float *k_data = input_k_blob->mutable_cpu_data();
167 for (size_t i = 0; i < 3; ++i) {
168 for (size_t j = 0; j < 3; ++j) {
169 k_data[i * 3 + j] = camera_k_matrix(i, j);
170 }
171 }
172 AINFO << "Camera k matrix input to obstacle postprocessor: \n"
173 << k_data[0] << ", " << k_data[1] << ", " << k_data[2] << "\n"
174 << k_data[3] << ", " << k_data[4] << ", " << k_data[5] << "\n"
175 << k_data[6] << ", " << k_data[7] << ", " << k_data[8] << "\n";
176
177 // Input ratio
178 float *ratio_data = input_ratio_blob->mutable_cpu_data();
179 ratio_data[0] = 4.f * static_cast<float>(frame->data_provider->src_width()) /
180 static_cast<float>(width_);
181 ratio_data[1] = 4.f * static_cast<float>(frame->data_provider->src_height()) /
182 static_cast<float>(height_);
183
184 // Input image
185 DataProvider::ImageOptions image_options;
186 image_options.target_color = base::Color::RGB;
187 image_options.crop_roi = base::RectI(0, offset_y_, options_.image_width,
188 options_.image_height - offset_y_);
189 image_options.do_crop = true;
190 // todo(daohu527) copy assignment
191 image_ = std::make_shared<base::Image8U>();
192 frame->data_provider->GetImage(image_options, image_.get());
193
194 // Preprocess
195 PERF_BLOCK("camera_3d_detector_preprocess")
196 Preprocess(image_.get(), input_blob);
198
199 // Net forward
200 PERF_BLOCK("camera_3d_detector_infer")
201 net_->Infer();
203
204 // Output
205 auto model_outputs = model_param_.info().outputs();
206 auto detection_blob = net_->get_blob(model_outputs[0].name());
207
208 PERF_BLOCK("camera_3d_detector_get_obj")
209 GetObjectsCpu(detection_blob, types_, model_param_, &frame->detected_objects,
210 frame->data_provider->src_width(),
211 frame->data_provider->src_height() - offset_y_);
213
214 FilterByMinDims(min_dims_, &frame->detected_objects);
215
216 RecoverBBox(frame->data_provider->src_width(),
217 frame->data_provider->src_height() - offset_y_, offset_y_,
218 &frame->detected_objects);
219
220 // appearance features for tracking
221 frame->feature_blob = net_->get_blob(model_outputs[1].name());
222
223 // post processing
224 for (auto &obj : frame->detected_objects) {
225 // recover alpha
226 obj->camera_supplement.alpha /= ori_cycle_;
227 }
228
229 return true;
230}
std::shared_ptr< inference::Inference > net_
bool Preprocess(const base::Image8U *image, std::shared_ptr< base::Blob< float > > input_blob)
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
Rect< int > RectI
Definition box.h:159
void GetObjectsCpu(const std::shared_ptr< base::Blob< float > > &output_blob, const std::vector< base::ObjectSubType > &types, const smoke::ModelParam &model_param, std::vector< base::ObjectPtr > *objects, int width, int height)
void FilterByMinDims(const smoke::MinDims &min_dims, std::vector< base::ObjectPtr > *objects)
void RecoverBBox(int roi_w, int roi_h, int offset_y, std::vector< base::ObjectPtr > *objects)
#define PERF_BLOCK_END
Definition profiler.h:53
#define PERF_BLOCK(...)
Definition profiler.h:52

◆ Init()

bool apollo::perception::camera::SmokeObstacleDetector::Init ( const ObstacleDetectorInitOptions options)
overridevirtual

Init function for SmokeObstacleDetector

参数
options
返回
true
false

实现了 apollo::perception::camera::BaseObstacleDetector.

在文件 smoke_obstacle_detector.cc80 行定义.

80 {
81 options_ = options;
82
83 std::string config_file =
84 GetConfigFile(options_.config_path, options_.config_file);
85 if (!cyber::common::GetProtoFromFile(config_file, &model_param_)) {
86 AERROR << "Read model param failed!";
87 return false;
88 }
89
90 InitImageOffset(model_param_);
91 InitImageSize(model_param_);
92 InitParam(model_param_);
94
95 const auto &model_info = model_param_.info();
96 std::string model_path = GetModelPath(model_info.name());
97
98 if (!InitNetwork(model_param_.info(), model_path)) {
99 AERROR << "Init network failed!";
100 return false;
101 }
102
103 return true;
104}
virtual bool InitNetwork(const common::ModelInfo &model_info, const std::string &model_root)
Interface for network initialization
void InitParam(const smoke::ModelParam &model_param)
void InitImageSize(const smoke::ModelParam &model_param)
void InitImageOffset(const smoke::ModelParam &model_param)
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80
std::string GetModelPath(const std::string &model_name)
Get the model path by model name, search from APOLLO_MODEL_PATH
Definition util.cc:44

◆ InitImageOffset()

void apollo::perception::camera::SmokeObstacleDetector::InitImageOffset ( const smoke::ModelParam model_param)
protected

在文件 smoke_obstacle_detector.cc31 行定义.

32 {
33 // offset
34 auto offset_ratio = model_param.offset_ratio();
35 int image_width = options_.image_width;
36 int image_height = options_.image_height;
37 offset_y_ = static_cast<int>(image_height * offset_ratio.y());
38 AINFO << "image_width=" << image_width << ", "
39 << "image_height=" << image_height << ", "
40 << "offset_y=" << offset_y_ << ", ";
41}

◆ InitImageSize()

void apollo::perception::camera::SmokeObstacleDetector::InitImageSize ( const smoke::ModelParam model_param)
protected

在文件 smoke_obstacle_detector.cc53 行定义.

54 {
55 // resize
56 auto resize = model_param.resize();
57 if (resize.width() == 0 && resize.height() == 0) {
58 width_ = options_.image_width * resize.fx();
59 height_ = options_.image_height * resize.fy();
60 } else {
61 width_ = resize.width();
62 height_ = resize.height();
63 }
64
65 AINFO << "height=" << height_ << ", "
66 << "width=" << width_;
67}

◆ InitObstacleTypes()

◆ InitParam()

void apollo::perception::camera::SmokeObstacleDetector::InitParam ( const smoke::ModelParam model_param)
protected

在文件 smoke_obstacle_detector.cc69 行定义.

69 {
70 // min 2d height
71 min_dims_ = model_param.min_dims();
72 // confidence threshold
73 confidence_threshold_ = model_param.confidence_threshold();
74 // ori cycle
75 ori_cycle_ = model_param.ori_cycle();
76 // border ratio
77 border_ratio_ = model_param.border_ratio();
78}

◆ Name()

std::string apollo::perception::camera::SmokeObstacleDetector::Name ( ) const
inlineoverridevirtual

Interface for obstacle detector name

返回
std::string

实现了 apollo::perception::camera::BaseObstacleDetector.

在文件 smoke_obstacle_detector.h55 行定义.

55{ return "SmokeObstacleDetector"; }

◆ Preprocess()

bool apollo::perception::camera::SmokeObstacleDetector::Preprocess ( const base::Image8U image,
std::shared_ptr< base::Blob< float > >  input_blob 
)
protected

在文件 smoke_obstacle_detector.cc106 行定义.

107 {
108 cv::Mat img = cv::Mat(image->rows(), image->cols(), CV_8UC3);
109 memcpy(img.data, image->cpu_data(),
110 image->rows() * image->cols() * image->channels() * sizeof(uint8_t));
111
112 // resize
113 cv::resize(img, img, cv::Size(width_, height_));
114
115 // mean and std
116 img.convertTo(img, CV_32F, 1.0 / 255, 0);
117 std::vector<float> mean_values{0, 0, 0};
118 std::vector<float> std_values{0.229, 0.224, 0.225};
119
120 std::vector<cv::Mat> rgbChannels(3);
121 cv::split(img, rgbChannels);
122 for (int i = 0; i < 3; ++i) {
123 rgbChannels[i].convertTo(rgbChannels[i], CV_32FC1, 1 / std_values[i],
124 (0.0 - mean_values[i]) / std_values[i]);
125 }
126 cv::merge(rgbChannels, img);
127
128 // from hwc to chw
129 int rows = img.rows;
130 int cols = img.cols;
131 int chs = img.channels();
132
133 // fill input_blob
134 input_blob->Reshape({1, chs, rows, cols});
135 float *input_data = input_blob->mutable_cpu_data();
136 for (int i = 0; i < chs; ++i) {
137 cv::extractChannel(
138 img, cv::Mat(rows, cols, CV_32FC1, input_data + i * rows * cols), i);
139 }
140 return true;
141}

该类的文档由以下文件生成: