首页 > 代码库 > opencv里用calcCovarMatrix计算协方差矩阵
opencv里用calcCovarMatrix计算协方差矩阵
Mat_<double> temp1(10, 3); Mat_<double> mean1, cov1; temp1(0, 0) = 49; temp1(0, 1) = 7; temp1(0, 2) = 29; temp1(1, 0) = 8; temp1(1, 1) = 19; temp1(1, 2) = 16; temp1(2, 0) = 12; temp1(2, 1) = 8; temp1(2, 2) = 14; temp1(3, 0) = 19; temp1(3, 1) = 37; temp1(3, 2) = 22; temp1(4, 0) = 3; temp1(4, 1) = 43; temp1(4, 2) = 21; temp1(5, 0) = 34; temp1(5, 1) = 17; temp1(5, 2) = 17; temp1(6, 0) = 20; temp1(6, 1) = 34; temp1(6, 2) = 27; temp1(7, 0) = 49; temp1(7, 1) = 14; temp1(7, 2) = 37; temp1(8, 0) = 20; temp1(8, 1) = 26; temp1(8, 2) = 21; temp1(9, 0) = 31; temp1(9, 1) = 41; temp1(9, 2) = 21; calcCovarMatrix(temp1, cov1, mean1, CV_COVAR_NORMAL | CV_COVAR_ROWS); cout << mean1 << endl; cout << cov1/9 << endl;
这样算出来的结果和matlab是一样的,
如果最后不除以9(样本数减1),则得不到正确的协方差矩阵。另外flag中如果加上CV_COVAR_SCALE,则相当于除以10(样本数)。
opencv里用calcCovarMatrix计算协方差矩阵
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。