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

#include <denseline_lane_detector.h>

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

Public 成员函数

 DenselineLaneDetector ()
 
virtual ~DenselineLaneDetector ()=default
 
bool Init (const LaneDetectorInitOptions &options=LaneDetectorInitOptions()) override
 
bool Detect (const LaneDetectorOptions &options, CameraFrame *frame) override
 
std::string Name () const override
 
- Public 成员函数 继承自 apollo::perception::camera::BaseLaneDetector
 BaseLaneDetector ()=default
 
virtual ~BaseLaneDetector ()=default
 
 DISALLOW_COPY_AND_ASSIGN (BaseLaneDetector)
 

详细描述

在文件 denseline_lane_detector.h39 行定义.

构造及析构函数说明

◆ DenselineLaneDetector()

apollo::perception::camera::DenselineLaneDetector::DenselineLaneDetector ( )
inline

在文件 denseline_lane_detector.h41 行定义.

42 input_height_ = 0;
43 input_width_ = 0;
44 input_offset_y_ = 0;
45 input_offset_x_ = 0;
46 crop_height_ = 0;
47 crop_width_ = 0;
48 resize_height_ = 0;
49 resize_width_ = 0;
50 image_mean_[0] = 0;
51 image_mean_[1] = 0;
52 image_mean_[2] = 0;
53 image_scale_ = 0;
54 }

◆ ~DenselineLaneDetector()

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

成员函数说明

◆ Detect()

bool apollo::perception::camera::DenselineLaneDetector::Detect ( const LaneDetectorOptions options,
CameraFrame frame 
)
overridevirtual

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

在文件 denseline_lane_detector.cc150 行定义.

151 {
152 if (frame == nullptr) {
153 AINFO << "camera frame is empty.";
154 return false;
155 }
156
157 auto data_provider = frame->data_provider;
158 if (input_width_ != data_provider->src_width()) {
159 AERROR << "Input size is not correct: " << input_width_ << " vs "
160 << data_provider->src_width();
161 return false;
162 }
163 if (input_height_ != data_provider->src_height()) {
164 AERROR << "Input size is not correct: " << input_height_ << " vs "
165 << data_provider->src_height();
166 return false;
167 }
168
169 if (!data_provider->GetImage(data_provider_image_option_, &image_src_)) {
170 return false;
171 }
172
173 // bottom 0 is data
174 auto input_blob = rt_net_->get_blob(net_inputs_[0]);
175 auto blob_channel = input_blob->channels();
176 auto blob_height = input_blob->height();
177 auto blob_width = input_blob->width();
178 AINFO << "input_blob: " << blob_channel << " " << blob_height << " "
179 << blob_width << std::endl;
180
181 if (blob_height != resize_height_) {
182 AERROR << "height is not equal" << blob_height << " vs " << resize_height_;
183 return false;
184 }
185 if (blob_width != resize_width_) {
186 AERROR << "width is not equal" << blob_width << " vs " << resize_width_;
187 return false;
188 }
189 ADEBUG << "image_blob: " << image_src_.blob()->shape_string();
190 ADEBUG << "input_blob: " << input_blob->shape_string();
191
193 image_src_, input_blob, static_cast<int>(crop_width_), 0,
194 static_cast<float>(image_mean_[0]), static_cast<float>(image_mean_[1]),
195 static_cast<float>(image_mean_[2]), false, static_cast<float>(1.0));
196 AINFO << "resize gpu finish.";
197 cudaDeviceSynchronize();
198 rt_net_->Infer();
199 AINFO << "infer finish.";
200
201 frame->lane_detected_blob = rt_net_->get_blob(net_outputs_[0]);
202 ADEBUG << frame->lane_detected_blob->shape_string();
203 return true;
204}
std::shared_ptr< Blob< uint8_t > > blob()
Definition image_8u.h:133
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
bool ResizeGPU(const base::Image8U &src, std::shared_ptr< apollo::perception::base::Blob< float > > dst, int stepwidth, int start_axis)

◆ Init()

bool apollo::perception::camera::DenselineLaneDetector::Init ( const LaneDetectorInitOptions options = LaneDetectorInitOptions())
overridevirtual

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

在文件 denseline_lane_detector.cc33 行定义.

33 {
34 std::string config_file =
35 GetConfigFile(options.config_path, options.config_file);
36 if (!cyber::common::GetProtoFromFile(config_file, &denseline_param_)) {
37 AINFO << "load proto param failed, root dir: " << config_file;
38 return false;
39 }
40
41 AINFO << "denseline param: " << denseline_param_.DebugString();
42
43 const auto model_param = denseline_param_.model_param();
44 std::string model_path = GetModelPath(model_param.model_name());
45
46 std::string proto_file = GetModelFile(model_path, model_param.proto_file());
47 std::string weight_file = GetModelFile(model_path, model_param.weight_file());
48
49 base_camera_model_ = options.base_camera_model;
50 if (base_camera_model_ == nullptr) {
51 AERROR << "options.intrinsic is nullptr!";
52 input_height_ = 1080;
53 input_width_ = 1920;
54 } else {
55 input_height_ = static_cast<uint16_t>(base_camera_model_->get_height());
56 input_width_ = static_cast<uint16_t>(base_camera_model_->get_width());
57 }
58 ACHECK(input_width_ > 0) << "input width should be more than 0";
59 ACHECK(input_height_ > 0) << "input height should be more than 0";
60
61 AINFO << "input_height: " << input_height_;
62 AINFO << "input_width: " << input_width_;
63
64 image_scale_ = model_param.resize_scale();
65 input_offset_y_ = static_cast<uint16_t>(model_param.input_offset_y());
66 input_offset_x_ = static_cast<uint16_t>(model_param.input_offset_x());
67 crop_height_ = static_cast<uint16_t>(model_param.crop_height());
68 crop_width_ = static_cast<uint16_t>(model_param.crop_width());
69
70 CHECK_LE(crop_height_, input_height_)
71 << "crop height larger than input height";
72 CHECK_LE(crop_width_, input_width_) << "crop width larger than input width";
73
74 if (model_param.is_bgr()) {
75 data_provider_image_option_.target_color = base::Color::BGR;
76 image_mean_[0] = model_param.mean_b();
77 image_mean_[1] = model_param.mean_g();
78 image_mean_[2] = model_param.mean_r();
79 } else {
80 data_provider_image_option_.target_color = base::Color::RGB;
81 image_mean_[0] = model_param.mean_r();
82 image_mean_[1] = model_param.mean_g();
83 image_mean_[2] = model_param.mean_b();
84 }
85 data_provider_image_option_.do_crop = true;
86 data_provider_image_option_.crop_roi.x = input_offset_x_;
87 data_provider_image_option_.crop_roi.y = input_offset_y_;
88 data_provider_image_option_.crop_roi.height = crop_height_;
89 data_provider_image_option_.crop_roi.width = crop_width_;
90
91 cudaDeviceProp prop;
92 cudaGetDeviceProperties(&prop, options.gpu_id);
93 AINFO << "GPU: " << prop.name;
94
95 const auto net_param = denseline_param_.net_param();
96 net_inputs_.push_back(net_param.in_blob());
97 net_outputs_.push_back(net_param.out_blob());
98 std::copy(net_param.internal_blob_int8().begin(),
99 net_param.internal_blob_int8().end(),
100 std::back_inserter(net_outputs_));
101
102 for (auto name : net_inputs_) {
103 AINFO << "net input blobs: " << name;
104 }
105 for (auto name : net_outputs_) {
106 AINFO << "net output blobs: " << name;
107 }
108
109 const auto &model_type = model_param.model_type();
110 AINFO << "model_type: " << model_type;
111 rt_net_.reset(inference::CreateInferenceByName(model_type, proto_file,
112 weight_file, net_outputs_,
113 net_inputs_, model_path));
114 ACHECK(rt_net_ != nullptr);
115 rt_net_->set_gpu_id(options.gpu_id);
116
117 resize_height_ = static_cast<uint16_t>(crop_height_ * image_scale_);
118 resize_width_ = static_cast<uint16_t>(crop_width_ * image_scale_);
119 ACHECK(resize_width_ > 0) << "resize width should be more than 0";
120 ACHECK(resize_height_ > 0) << "resize height should be more than 0";
121
122 std::vector<int> shape = {1, 3, resize_height_, resize_width_};
123
124 std::map<std::string, std::vector<int>> input_reshape{
125 {net_inputs_[0], shape}};
126 AINFO << "input_reshape: " << input_reshape[net_inputs_[0]][0] << ", "
127 << input_reshape[net_inputs_[0]][1] << ", "
128 << input_reshape[net_inputs_[0]][2] << ", "
129 << input_reshape[net_inputs_[0]][3];
130 if (!rt_net_->Init(input_reshape)) {
131 AINFO << "net init fail.";
132 return false;
133 }
134
135 for (auto &input_blob_name : net_inputs_) {
136 auto input_blob = rt_net_->get_blob(input_blob_name);
137 AINFO << input_blob_name << ": " << input_blob->channels() << " "
138 << input_blob->height() << " " << input_blob->width();
139 }
140
141 for (auto &output_blob_name : net_outputs_) {
142 auto output_blob = rt_net_->get_blob(output_blob_name);
143 AINFO << output_blob_name << " : " << output_blob->channels() << " "
144 << output_blob->height() << " " << output_blob->width();
145 }
146
147 return true;
148}
#define ACHECK(cond)
Definition log.h:80
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
Inference * CreateInferenceByName(const std::string &frame_work, const std::string &proto_file, const std::string &weight_file, const std::vector< std::string > &outputs, const std::vector< std::string > &inputs, const std::string &model_root)
std::string GetModelFile(const std::string &model_name, const std::string &file_name)
Get the model file path by model path and file name
Definition util.cc:55
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

◆ Name()

std::string apollo::perception::camera::DenselineLaneDetector::Name ( ) const
overridevirtual

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

在文件 denseline_lane_detector.cc206 行定义.

206 {
207 return "DenselineLaneDetector";
208}

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