Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6813 ディスカッション

Finiding the coefficients of a transform matrix

giora1
ビギナー
675件の閲覧回数
Hi,
I am currentlly using the ippi library for computer vision.
I perform geometric transforms using the following functions:
ippiWarpBilinearQuad
ippiWarpAffineQuad
Does anyone know of a way to get the coefficients ofthe matrixs used in thesetransformations?
Thanks in advance,
Giora
0 件の賞賛
4 返答(返信)
Intel_C_Intel
従業員
675件の閲覧回数

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

giora1
ビギナー
675件の閲覧回数

Dear Alexander,

Thanks for your answer. Unfortunately my argumant is not rectangular.

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

Thanks again,

Giora

Vladimir_Dudnik
従業員
675件の閲覧回数

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,
Vladimir

giora1
ビギナー
675件の閲覧回数

Hi Vladimir,

Thanks for your detailed answer - this might do the work for me.

Regards,

Giora

返信