Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

asked 2014-02-19 04:56:10 -0600

berak gravatar image

trouble with calcCovarMatrix

i'm trying to port some matlab code, part of it involves getting the covariance matrix


octave example:


octave:1> A=[-1, 1, 2; -2, 3, 1; 4, 0, 3;]
A =

  -1   1   2
  -2   3   1
   4   0   3

octave:2> cov(A)
ans =

   10.3333   -4.1667    3.0000
   -4.1667    2.3333   -1.5000
    3.0000   -1.5000    1.0000

opencv version:


Mat_<double> A(3,3);  f << -1, 1, 2, -2, 3, 1 , 4, 0, 3;
Mat Sw, mea;
calcCovarMatrix( A, Sw, mea, cv::COVAR_NORMAL|cv::COVAR_ROWS );
cerr << Sw << endl;

[20.66666666666666, -8.333333333333334, 6;
 -8.333333333333334, 4.666666666666667, -3;
 6, -3, 2]

as you can see, similar, but a factor 2 in the opencv version .

any obvious mistake here ?

trouble with calcCovarMatrix

i'm trying to port some matlab code, part of it involves getting the covariance matrix


octave example:


octave:1> A=[-1, 1, 2; -2, 3, 1; 4, 0, 3;]
A =

  -1   1   2
  -2   3   1
   4   0   3

octave:2> cov(A)
ans =

   10.3333   -4.1667    3.0000
   -4.1667    2.3333   -1.5000
    3.0000   -1.5000    1.0000

opencv version:


Mat_<double> A(3,3);  f A << -1, 1, 2, -2, 3, 1 , 4, 0, 3;
Mat Sw, mea;
calcCovarMatrix( A, Sw, mea, cv::COVAR_NORMAL|cv::COVAR_ROWS );
cerr << Sw << endl;

[20.66666666666666, -8.333333333333334, 6;
 -8.333333333333334, 4.666666666666667, -3;
 6, -3, 2]

as you can see, similar, but a factor 2 in the opencv version .

any obvious mistake here ?