(八)OpenCV人脸识别_01_方差与协方差

Belle ·
更新时间:2024-11-13
· 627 次阅读

计算N维数据的平均值meanStdDev(均值及标准差)
方差
协方差calcCovarMatrix

#include #include #include using namespace std; using namespace cv; int main(int argc, char** argv) { Mat src; src = imread("../path.jpg"); if (src.empty()) { cout << "could not load image..." << endl; return -1; } namedWindow("src", WINDOW_AUTOSIZE); imshow("src", src); Mat mean, stddev; //计算矩阵的均值及标准差//标准差只是协方差矩阵的对角元素,如果要计算协方差矩阵,要使用calcCovarMatrix() meanStdDev(src, mean, stddev); //3通道 cout << "均值矩阵行数: " << mean.rows << endl; cout << "均值矩阵列数: " << mean.cols << endl; cout << "标准差矩阵行数: " << stddev.rows << endl; cout << "标准差矩阵列数: " << stddev.cols << endl; cout << "均值mean矩阵为: " << endl; for (int row = 0; row < mean.rows ; row++) { cout << mean.at(row) << endl; } cout << "标准差stddev矩阵为: " << endl; for (int row = 0; row < stddev.rows; row++) { cout << stddev.at(row) << endl; } Mat samples = (Mat_(5,3) < 变量相同则为方差 calcCovarMatrix(samples, covar, means, COVAR_NORMAL | COVAR_ROWS); cout << endl; cout << "矩阵协方差矩阵covar: " << endl << covar/5 << endl; cout << "矩阵均值mean: " << endl << means << endl; waitKey(0); return 0; }

输出结果:
在这里插入图片描述


作者:丶小早



方差 opencv人脸识别 opencv 协方差

需要 登录 后方可回复, 如果你还没有账号请 注册新账号