...
// init bm images for storing results of combined operation of resize & crop & split
ret = bm_image_create_batch(bm_handle_,
INPUT_HEIGHT,
INPUT_WIDTH,
FORMAT_BGR_PLANAR,
DATA_TYPE_EXT_1N_BYTE,
resize_bmcv_,
MAX_BATCH);
if (!ret) {
cout << "ERROR: bm_image_create_batch failed" << endl;
exit(1);
}
// bm images for storing inference inputs
bm_image_data_format_ext data_type;
if (is_int8_) { // INT8
data_type = DATA_TYPE_EXT_1N_BYTE_SIGNED;
} else { // FP32
data_type = DATA_TYPE_EXT_FLOAT32;
}
ret = bm_image_create_batch (bm_handle_,
INPUT_HEIGHT,
INPUT_WIDTH,
FORMAT_BGR_PLANAR,
data_type,
linear_trans_bmcv_,
MAX_BATCH);
if (!ret) {
cout << "ERROR: bm_image_create_batch failed" << endl;
exit(1);
}
...
...
// init linear transform parameter, X*a + b, int8 model need to consider scales
if (is_int8_) {
float input_scale = net_info_->input_scales[0];
linear_trans_param_.alpha_0 = input_scale;
linear_trans_param_.beta_0 = -123.0 * input_scale;
linear_trans_param_.alpha_1 = input_scale;
linear_trans_param_.beta_1 = -117.0 * input_scale;
linear_trans_param_.alpha_2 = input_scale;
linear_trans_param_.beta_2 = -104.0 * input_scale;
}
...
...
// open stream
cv::VideoCapture cap(input_url);
if (!cap.isOpened()) {
cout << "open stream " << input_url << " failed!" << endl;
exit(1);
}
// get resolution
int w = int(cap.get(cv::CAP_PROP_FRAME_WIDTH));
int h = int(cap.get(cv::CAP_PROP_FRAME_HEIGHT));
cout << "resolution of input stream: " << h << "," << w << endl;
// set output format to YUVi420
cap.set(cv::CAP_PROP_OUTPUT_YUV, 1.0);
...
...
// get one mat
cap.read(*p_img);
// sanity check
if (p_img->avRows() != h || p_img->avCols() != w) {
if (p_img != nullptr) delete p_img;
continue;
}
...
...
bm_image_from_mat (bm_handle, images, input_img_bmcv);
...
for (size_t i = 0; i < input_img_bmcv.size();i++) {
bm_image_destroy (input_img_bmcv[i]);
}
...
...
// set input shape according to input bm images
input_shape_ = {4, {(int)input.size(), 3, INPUT_HEIGHT, INPUT_WIDTH}};
// do not crop
crop_rect_ = {0, 0, input[0].width, input[0].height};
// resize && split by bmcv
for (size_t i = 0; i < input.size(); i++) {
LOG_TS(ts_, "ssd pre-process-vpp")
bmcv_image_vpp_convert (bm_handle_, 1, input[i], &resize_bmcv_[i], &crop_rect_);
LOG_TS(ts_, "ssd pre-process-vpp")
}
// do linear transform
LOG_TS(ts_, "ssd pre-process-linear_tranform")
bmcv_convert_to (bm_handle_, input.size(), linear_trans_param_, resize_bmcv_, linear_trans_bmcv_);
LOG_TS(ts_, "ssd pre-process-linear_tranform")
...