Opencv C++下的Mat归一化
void Mat_L2_mormal(cv::Mat &image)
{
//mat*mat,
cv::Mat out;
out=(image) .mul (image);
float sum=0.0;
for (int i=0;i<image.rows;i++){
sum=sqrt(cv::sum(out.row(i))[0]);
image.row(i)=(image.row(i)/sum);
}
out.release();
}
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;
}
}
}
这个也是减均值128,归一化
cv::cvtColor(imgResized, imgResized, cv::COLOR_RGB2BGR);
//Mat_L2_mormal(imgResized);
vector<Mat> bgr;
cv::split(imgResized, bgr);
bgr[0].convertTo(bgr[0], CV_32F, 1.f / 128.f, -1.f);
bgr[1].convertTo(bgr[1], CV_32F, 1.f / 128.f, -1.f);
bgr[2].convertTo(bgr[2], CV_32F, 1.f / 128.f, -1.f);
来源:oschina
链接:https://my.oschina.net/u/4373527/blog/4282765