opencv学习日记——计算图像的平均值和标准差
mean函数的结果为 返回值;
meanStdDev函数的结果在函数里面。
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
float a[6] = {1, 2, 3, 4, 5, 6};
Mat img = Mat(3, 2, CV_32FC1, a);
Mat imgs = Mat(3, 2, CV_32FC2, a);
Scalar myMean;
myMean = mean(imgs);
cout << imgs << endl;
cout << myMean << endl;
cout << myMean[0] << endl;//第一个通道均值
cout << myMean[1] << endl;//第二个通道均值
Scalar myMeanStdDev;
Mat meanMat, stdDevMat;
meanStdDev(imgs, meanMat, stdDevMat);
cout << "imgs的平均值为: " << meanMat << endl;//均值
cout << "imgs的标准差为: " << stdDevMat << endl;//标准差
return 0;
}
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
[1, 2, 3, 4;
5, 6, 0, 0;
0, 1.9375, 0, 2]
[1.5, 2, 0, 0]
1.5
2
imgs的平均值为: [1.5;
2.65625]
imgs的标准差为: [1.892969448600091;
1.889440917088086]