Cross-covariance of 2 sample sets.

asked 2019-04-29 13:37:23 -0500

Kibouo gravatar image

updated 2019-05-01 07:41:11 -0500

calcCovarMarix works great for calculating the auto-covariance matrix of a given sample set.

Now, how does one calculate the cross-covariance of 2 sample sets?

Example: every row of a matrix is a sample. Samples are random vectors with possibly differing amount of variables:

Mat A = [[1, 2],
         [2, 3]]

Mat B = [[3, 4, 5],
         [4, 5, 6]]

In MATLAB one can simply do cov(A, B). How would one do it in C++ OpenCV?

edit retag flag offensive close merge delete



Did you miss

Or are you using C++?

sjhalayka gravatar imagesjhalayka ( 2019-04-29 19:33:56 -0500 )edit

My bad, I'm using C++. Edited Q.

Kibouo gravatar imageKibouo ( 2019-04-30 07:04:41 -0500 )edit

I found this as well:

Go to the section More About > Covariance.

Also check out:

Is that what you're looking for? If so, please let me know, and I'll see what I can do about writing some C++ code for you.

sjhalayka gravatar imagesjhalayka ( 2019-04-30 11:07:41 -0500 )edit

Yes, those resources are relevant.

The thing is, I could implement it myself from scratch using the definition found at .

However, it would probably be slow. And I expected something 'basic' as this to be present in OpenCV. Especially since calcCovarMatrix exists.

Kibouo gravatar imageKibouo ( 2019-04-30 11:12:37 -0500 )edit

again, please explain your use case, and your expectations.

berak gravatar imageberak ( 2019-05-01 02:08:56 -0500 )edit

The expectation should be pretty clear: I want the cross-covariance matrix of 2 sample sets, calculated using C++ OpenCV.

Kibouo gravatar imageKibouo ( 2019-05-01 07:40:09 -0500 )edit