ImageEn, unit IEVision

TIEVisionMath.getAffineTransform

TIEVisionMath.getAffineTransform

Declaration

function getAffineTransform(srcPoints: TIEVisionVectorPoint2f; dstPoints: TIEVisionVectorPoint2f): TIEVisionMatrix; safecall;

Description

Calculates the affine transformation (combination of move, scale, rotate and skew) that maps three source points exactly to three destination points.
Returns a 2x3 matrix (64 bit floating point values) for use with warpAffine.
Parameter Description
srcPoints Three points in the source image. They must not lie on one line
dstPoints The three positions they move to

The matrix maps a point (x, y) to:
x' = m[0, 0] * x + m[0, 1] * y + m[0, 2]
y' = m[1, 0] * x + m[1, 1] * y + m[1, 2]

The values can be read with PDoubleArray( M.getScanline( row ))[ col ].

Note: Raises an exception if either list does not contain exactly three points, or the source points are collinear

Demo

Demo  Demos\ImageEditing\EveryMethod\EveryMethod.dpr

Example

// Skew an image so that its top-left, top-right and bottom-left corners move to new positions
w := ImageEnView1.IEBitmap.Width;
h := ImageEnView1.IEBitmap.Height;
srcPoints := IEVisionLib().createVectorPoint2f();
srcPoints.push_back( IEVisionPoint2f( 0, 0 ));
srcPoints.push_back( IEVisionPoint2f( w, 0 ));
srcPoints.push_back( IEVisionPoint2f( 0, h ));
dstPoints := IEVisionLib().createVectorPoint2f();
dstPoints.push_back( IEVisionPoint2f( w * 0.1, h * 0.05 ));
dstPoints.push_back( IEVisionPoint2f( w * 0.9, 0 ));
dstPoints.push_back( IEVisionPoint2f( 0, h * 0.9 ));

M := IEVisionLib().createMath().getAffineTransform( srcPoints, dstPoints );
img := ImageEnView1.IEBitmap.GetIEVisionImage().warpAffine( M, IEVisionSize( w, h ));
ImageEnView1.IEBitmap.AssignIEVisionImage( img );

See Also

◼warpAffine
◼findHomography
◼delaunayTriangulation