SB26
SB26

Reputation: 225

Error using calcCovarMatrix in openCv

I am trying to calculate the covariance matrix in my code but I am getting an error doing that. I have the array of mean values which I want to use. Here is my code

Mat Zt(Z);
Mat Zttranspose;
Mat covarZ=cvCreateMat(image->nChannels,image->nChannels,CV_32FC1);

Zttranspose=Zt.t();

Mat_<float> arraymean=(Mat_<float>(3,3)<< meanb, meang, meanr);

calcCovarMatrix(Zt,covarZ,arraymean,CV_COVAR_USE_AVG,CV_64F)

But I get the following error:

OpenCV Error: Assertion failed (((flags & CV_COVAR_ROWS) != 0) ^ ((flags & CV_COVAR_COLS) != 0)) in calcCovarMatrix, file /usr/local/src/OpenCV-2.3.0/modules/core/src/matmul.cpp, line 2127 terminate called after throwing an instance of 'cv::Exception'

Upvotes: 1

Views: 1924

Answers (3)

alternatefaraz
alternatefaraz

Reputation: 374

This will solve your problem

-

calcCovarMatrix(Zt,covarZ,arraymean,CV_COVAR_USE_AVG | CV_COVAR_ROWS,CV_64F)

Upvotes: 0

BajaBob
BajaBob

Reputation: 1

You're creating the matrix with CV_32FC1 and then calling calcCovarMatrix with CV_64F - you need to make them consistent for starters.

Upvotes: 0

Mzk
Mzk

Reputation: 1120

Mat covarZ=cvCreateMat(..); I think you have mix out with C and C++ API.

You might want to have a look at this link http://pastebin.com/cWQi4ngv.

I have tried and it works.

Upvotes: 2

Related Questions