Monday, August 10, 2009

Be careful to use cvGetSubRect, cvGetRow and cvGetCol

When you uses these three function or similar function which have cvGetXX part, you must be careful. It return the pointer to return matrix, if you change the value of return matrix, the mother of this submatrix will be changed too. For example:

float a[]={1,2,3,4};
CvMat A=cvMat(2,2,CV_32FC1);
CvMat* B=cvCreateMat(1,2,CV_32FC1);

cvGetRow(&A,B,0);

Of course, here B->data={1,2};
But if we do:

CV_MAT_ELEM(B,float,0,0)=100;

Then you can check the first element of matrix A or array a become 100!!

So Now we understand, these function return the pointer. It gives the first pointer of first row of A to B. But we already give a new space to B, this part of space is not used anymore because the pointer of B is not pointer to "CvMat* B=cvCreateMat(1,2,CV_32FC1);" anymore. We also can not release the B afterwards as it pointer the content of A.
So these three functions are for operation on mother matrix, but not for get content of A.

So the correct way to get a row from A is:
float a[]={1,2,3,4};
CvMat A=cvMat(2,2,CV_32FC1);
CvMat* B=cvCreateMat(1,2,CV_32FC1);

CvMat tmp;

cvGetRow(&A,tmp,0);
cvCopy(&tmp,B);

cvReleaseMat(&B);


Here we go.

Friday, August 7, 2009

How to use ffmpeg extract freams from video file

ffmpeg is a power tool.
Here is a method.

ffmpeg -i input.avi -r 10 -f image2 images%05d.png

Here input.avi is input video file.
10 is fps.
image2 is image format.
%05d means that it has five numbers behind images. eg.images99999.png

How to use svn to see difference between two version

The method is :

svn diff -r2:19

2 and 19 are version number. But first need update your working copy before you do it.