Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

for the covariance:

Mat_<float> samples = (Mat_<float>(3, 2) << 500.0, 350.2, 500.5, 355.8, 498.7, 352.0);

Mat cov, mu;
cv::calcCovarMatrix(samples, cov, mu, CV_COVAR_NORMAL | CV_COVAR_ROWS);

cov = cov / (samples.rows - 1);

cout << "cov: " << endl;
cout << cov << endl;

cout << "mu: " << endl;
cout << mu << endl;

result:

cov: 
[0.8633207194507122, 1.216659545898438;
 1.216659545898438, 8.173264974107346]
mu: 
[499.7333374023438, 352.6666666666666]

for the covariance:

Mat_<float> samples = (Mat_<float>(3, 2) << 500.0, 350.2,
                                             500.5, 355.8,
                                             498.7, 352.0);

352.0);
Mat cov, mu;
cv::calcCovarMatrix(samples, cov, mu, CV_COVAR_NORMAL | CV_COVAR_ROWS);

cov = cov / (samples.rows - 1);

cout << "cov: " << endl;
cout << cov << endl;

cout << "mu: " << endl;
cout << mu << endl;

result:

cov: 
[0.8633207194507122, 1.216659545898438;
 1.216659545898438, 8.173264974107346]
mu: 
[499.7333374023438, 352.6666666666666]