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
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
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
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
185 DataProvider::ImageOptions image_options;
189 image_options.do_crop = true;
190
191 image_ = std::make_shared<base::Image8U>();
192 frame->data_provider->GetImage(image_options, image_.get());
193
194
198
199
203
204
205 auto model_outputs = model_param_.info().outputs();
206 auto detection_blob =
net_->get_blob(model_outputs[0].name());
207
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
215
217 frame->data_provider->src_height() - offset_y_, offset_y_,
218 &frame->detected_objects);
219
220
221 frame->feature_blob =
net_->get_blob(model_outputs[1].name());
222
223
224 for (auto &obj : frame->detected_objects) {
225
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)
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)
Eigen::Matrix3f intrinsic
optional common::ModelInfo info