Intel® Integrated Performance Primitives
Community support and discussions relating to developing high-performance vision, signal, security, and storage applications.
Announcements
6664 Discussions

## Finiding the coefficients of a transform matrix

Beginner
214 Views
Hi,
I am currentlly using the ippi library for computer vision.
I perform geometric transforms using the following functions:
Does anyone know of a way to get the coefficients ofthe matrixs used in thesetransformations?
Giora
4 Replies
Employee
214 Views

Hi, Giora,

It could be done by ippiGetAffine/BilinearTransform function if your argument quadrangle is a rectangle. In other case some matrix manipulation are necessary

Eg for affine transform you could form and solve the system of 6 linear equations for 3 of quadrangle corners. Pixel indices are coordinates:

x0'=c00*x0+c01*y0+c02

y0'=c10*x0+c11*y0+c12 etc

Alexander

Beginner
214 Views

Dear Alexander,

Do you know what functions in IPP can help me to solve the system of 6 linear equations?

Thanks again,

Giora

Employee
214 Views

Hi,

there is OpenCV sample for general case

Code:

```/* Calculates coefficients of perspective transformation
* which maps (xi,yi) to (ui,vi), (i=1,2,3,4):
*
*      c00*xi + c01*yi + c02
* ui = ---------------------
*      c20*xi + c21*yi + c22
*
*      c10*xi + c11*yi + c12
* vi = ---------------------
*      c20*xi + c21*yi + c22
*
* Coefficients are calculated by solving linear system:
* / 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/
*
* where:
*   cij - matrix coefficients, c22 = 1
*/
CV_IMPL CvMat*
cvWarpPerspectiveQMatrix( const CvPoint2D32f* src,
const CvPoint2D32f* dst,
CvMat* matrix )
{
CV_FUNCNAME( "cvGetPerspectiveTransformMatrix" );

__BEGIN__;

double a[8][8];
double b[8], x[9];

CvMat A = cvMat( 8, 8, CV_64FC1, a );
CvMat B = cvMat( 8, 1, CV_64FC1, b );
CvMat X = cvMat( 8, 1, CV_64FC1, x );

int i;

if( !src || !dst || !matrix )
CV_ERROR( CV_StsNullPtr, "" );

for( i = 0; i < 4; ++i )
{
a[0] = a[i+4][3] = src.x;
a[1] = a[i+4][4] = src.y;
a[2] = a[i+4][5] = 1;
a[3] = a[4] = a[5] =
a[i+4][0] = a[i+4][1] = a[i+4][2] = 0;
a[6] = -src.x*dst.x;
a[7] = -src.y*dst.x;
a[i+4][6] = -src.x*dst.y;
a[i+4][7] = -src.y*dst.y;
b = dst.x;
b[i+4] = dst.y;
}

cvSolve( &A, &B, &X, CV_SVD );
x[8] = 1;

X = cvMat( 3, 3, CV_64FC1, x );
cvConvert( &X, matrix );

__END__;

return matrix;
}```

Regards,