u=(A*x+B*y+C)/(G*x+H*y+1);
v=(D*x+E*y+F)/(G*x+H*y+1);
见下关系:
* / x0 y0 1 0 0 0 -x0*u0 -y0*u0 \ /c00\ /u0\
* | x1 y1 1 0 0 0 -x1*u1 -y1*u1 | |c01| |u1|
* | x2 y2 1 0 0 0 -x2*u2 -y2*u2 | |c02| |u2|
* | x3 y3 1 0 0 0 -x3*u3 -y3*u3 |.|c10|=|u3|,
* | 0 0 0 x0 y0 1 -x0*v0 -y0*v0 | |c11| |v0|
* | 0 0 0 x1 y1 1 -x1*v1 -y1*v1 | |c12| |v1|
* | 0 0 0 x2 y2 1 -x2*v2 -y2*v2 | |c20| |v2|
* \ 0 0 0 x3 y3 1 -x3*v3 -y3*v3 / \c21/ \v3/
int numPoints=10;
double **a=new double *[2*numPoints];
for(int i = 0; i <2*numPoints;i++)
a[i] = new double[8];
double *b =new double[2*numPoints];
CvMat A = cvMat (2*numPoints,8, CV_64F, a);
CvMat B = cvMat (2*numPoints,1, CV_64F, b);
CvMat *X = cvCreateMat (8, 1, CV_64F);
for( int i = 0; i <numPoints; ++i )
{
a[i][0] = a[i+numPoints][3] =points1[i].x;
a[i][1] = a[i+numPoints][4] =points1[i].y;
a[i][2] = a[i+numPoints][5] = 1;
a[i][3] = a[i][4] = a[i][5] =0;
a[i+numPoints][0] = a[i+numPoints][1] = a[i+numPoints][2] = 0;
a[i][6] = -points1[i].x*points2[i].x;
a[i][7] = -points1[i].y*points2[i].x;
a[i+numPoints][6] = -points1[i].x*points2[i].y;
a[i+numPoints][7] = -points1[i].y*points2[i].y;
b[i] =points2[i].x;
b[i+numPoints] =points2[i].y;
}
cvSolve(&A,&B,X,CV_SVD);
for(int i=0;i<8;i++)
cvmSet(H_Mat2,i/3,i%3,cvmGet(X,i,0));
cvmSet(H_Mat2,2,2,1.0);
for(int i = 0; i<2*numPoints;i++)
{
delete [8]a[i];
a[i]=NULL;
}
delete [2*numPoints]a;
delete [2*numPoints]b;
a=NULL;
b=NULL;