在C++进行深度学习推理时,需要对图像数据进行归一化处理,这里给出一个c++版本的归一化代码
float scale = 0.0078125f ;
float mean_value = 127.5f;
void Mat_L2_mormal(cv::Mat &image)
{
for (int i = 0; i<image.rows; i++)
{
for (int j = 0; j<image.cols; j++)
{
image.at<Vec3b>(i, j)[0] = (image.at<Vec3b>(i, j)[0] - mean_value) * scale;
image.at<Vec3b>(i, j)[1] = (image.at<Vec3b>(i, j)[1] - mean_value) * scale;
image.at<Vec3b>(i, j)[2] = (image.at<Vec3b>(i, j)[2] - mean_value) * scale;
}
}
}
|