# Cross-covariance of 2 sample sets.

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 close merge delete

1

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

I found this as well: https://www.mathworks.com/help/matlab...

Go to the section More About > Covariance.

Also check out: https://en.wikipedia.org/wiki/Cross-c...

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.

Yes, those resources are relevant.

The thing is, I could implement it myself from scratch using the definition found at https://en.wikipedia.org/wiki/Cross-c... .

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