0

I am trying to implement mahalanobis distance using OpenCV and VC++ 2010.

I know the algorithm for it, the function.

(x-mean)^T*inv(covarmatrix)*(x-mean)

But when I implement it in OpenCV it just gives errors over and over.

this is my code where I am calculating the covariance matrix.

int Main(){

    Mat Image;
    Mat, Cov,mean;
    float samples=1920000;
    calcCovarMatrix(image,samples,covmat,mean,CV_COVAR_NORMAL);
}

the calcCovarMatrix gives error:

no instance of overloaded function calcCovarMatrix matches the argument list.

After I would then do

vec3b pixel;
icovar=covmat^-1;
mdist = mahalanobis(vec3b,mean,icovar);

Note: I calculate mahalanobis distance without square root, but the above function does square root, how comes and also I will square it to make it fair as I did the same to get the threshold distance.

thanks

4

1 回答 1

2

第一个参数应该是 Mat* 所以它应该是 &image

请参阅http://docs.opencv.org/2.4.4/modules/core/doc/operations_on_arrays.html#void calcCovarMatrix(const Mat* samples, int nsamples, Mat& covar, Mat& mean, int flags, int ctype)

于 2013-06-11T14:17:31.780 回答