MNN工程化中,首先遇到图像预处理,其中要做的是对图像归一化,这里不需要我们自己用代码实现,MNN自动帮我们处理,代码如下,根据MNN回复,处理公式是 dst = (img - mean) * normal
#1、只除以均值255
std::vector<float> means{0, 0, 0};
std::vector<float> stds{1.0 / 255, 1.0 / 255, 1.0 / 255};
#2、均值方差
std::vector<float> means{255 * 0.408, 255 * 0.447, 255 * 0.470};
std::vector<float> stds{1.0 / (255*0.289), 1.0 / (255*0.274), 1.0 / (255*0.278)};
MNN::CV::ImageProcess::Config config;
::memcpy(config.mean, means.data(), 3*sizeof(float));
::memcpy(config.normal, stds.data(), 3*sizeof(float));
config.sourceFormat = MNN::CV::BGR;
config.destFormat = MNN::CV::RGB;
std::shared_ptr<MNN::CV::ImageProcess> pretreat(MNN::CV::ImageProcess::create(config));
pretreat->convert((uint8_t*)image.data,INPUTWIDTH,INPUTHEIGHT,0,nchwTensor);
input->copyFromHostTensor(nchwTensor);