function outputs different matrix

Pages: 12
I minimized so the for loop only contains two functions.
but still it seems to take 2 seconds per image.

 ``123456789101112131415161718192021222324`` `````` icovar=inversemat(covmat); while(1){ //copy webcam stream to image cap>>image; //print image to screen for(int i = 0; i < image.rows;i++) { for(int j=0;j(i,j); //own made inv matrix function mdist=mahadistance(icovar,meanmat,pixel); if(mdist>distance) mask.at(i,j)=255; else mask.at(i,j)=0; } } imshow("original",image); imshow("mask",mask);``````

but i don't understand why it is still taking long only 2 instructions in the loop and they execute pretty quickly it has a lot of commenting on it.
Do a quick test: replace mdist=mahadistance(icovar,meanmat,pixel); with mdist=0;
If it works fast, your problem is in mahadistance function. If you post that, someone might find a way to make it faster
Sorry, I noticed you posted it already. But please check your speed with mdist=0; Also, you can comment out line by line, see where is your problem.
Last edited on
Ok
so when i replaced mdist=mahadistance(icovar,meanmat,pixel) with mdist=0 it was moving pretty fast atleast several frames per second 2-3, but it was fast.

so something is wrong with my mahadisance calculation the function is below.

 ``123456789101112131415161718192021222324`` ``````double mahadistance(Mat invcov, Scalar meanvec, Vec3b patternvec) { double distmeasure=0; Scalar x1,x2; //mahalanobis distance is equal to (x-mean)^T*inv(cov)*(x-mean) x1[0]=(patternvec[0]-meanvec[0]); x1[1]=(patternvec[1]-meanvec[1]); x1[2]=(patternvec[2]-meanvec[2]); for(int k = 0; k < 3;k++) { x2[0]=x2[0]+(x1[k]*invcov.at(k,0)); x2[1]=x2[1]+(x1[k]*invcov.at(k,1)); //-1.#QNAN is element of inverse covariance matrix x2[2]=x2[2]+(x1[k]*invcov.at(k,2)); } //x2[0]=(x1[0]*invcov.at(1,1)+x1[1]*invcov.at(2,1)+x1[2]*invcov.at(3,1)); //x2[1]=(x1[0]*invcov.at(1,2)+x1[1]*invcov.at(2,2)+x1[2]*invcov.at(3,2)); //x2[2]=(x1[0]*invcov.at(1,3)+x1[1]*invcov.at(2,3)+x1[2]*invcov.at(3,3)); distmeasure=((x2[0]*x1[0])+(x2[1]*x1[1])+(x2[2]*x1[2])); return distmeasure; }``````

thanks
I can't see what is slowing this down, simple calculations.
Topic archived. No new replies allowed.
Pages: 12