ImageEn, unit IEVision

TIEVisionImage.warpPerspective

TIEVisionImage.warpPerspective

Declaration

function warpPerspective(M: TIEVisionMatrix; destSize: TIEVisionSize; interpolation: TIEVisionInterpolation = ievLINEAR; borderMode: TIEVisionBorderType = ievBORDER_CONSTANT; inverseMap: bool32 = False): TIEVisionImage; overload; safecall;
function warpPerspective(M: TIEVisionMatrix; destSize: TIEVisionSize; interpolation: TIEVisionInterpolation; borderMode: TIEVisionBorderType; const borderValue: TIEVisionScalar; inverseMap: bool32 = False): TIEVisionImage; overload; safecall;

Description

Apply a perspective transformation to an image.
Parameter Description
M 3x3 transformation matrix
destSize Size of the output image
interpolation Interpolation method (ievNEAREST or ievLINEAR)
borderMode Border mode (ievBORDER_CONSTANT or ievBORDER_REPLICATE)
borderValue Border color (B, G, R, 0)
inverseMap Sets M as the inverse transformation

Returns the warped image.

Using Homography to correct the perspective of an image:


Note:
◼This method will discard the AlphaChannel
◼A shortcut method for this is available: DetectAndDeskew

Demos

Demo  Demos\IEVision\ImageAlignment\ImageAlignment.dpr
Demo  Demos\ImageEditing\EveryMethod\EveryMethod.dpr

Examples

Also see: Automated Samples
// Warp img1 (TIEBitmap) using hmat matrix to a 1000x1000 bitmap
imgres := img1.GetIEVisionImage().warpPerspective(hmat, IEVisionSize(1000, 1000));
ImageEnView1.IEBitmap.AssignIEVisionImage(imgres);

// Warp img1 (TIEBitmap) using hmat matrix to a 1000x1000 bitmap, with a red (scalar 0,0,255,0) border
imgres := img1.GetIEVisionImage().warpPerspective(hmat, IEVisionSize(1000, 1000), ievNEAREST, ievBORDER_CONSTANT, IEVisionScalar(0, 0, 255, 0));
ImageEnView1.IEBitmap.AssignIEVisionImage(imgres);


// Load test image
ImageEnView1.IO.LoadFromFile( 'D:\TestImage.jpg' );

  

// Apply a keystone perspective by narrowing the top of the image by 20% on each side
w := ImageEnView1.IEBitmap.Width;
h := ImageEnView1.IEBitmap.Height;
inset := MulDiv( w, 20, 100 );

// Map the image corners (TL, TR, BR, BL) to a trapezoid
srcPoints := IEVisionLib().createVectorPoint2f();
dstPoints := IEVisionLib().createVectorPoint2f();
srcPoints.push_back( IEVisionPoint2f( 0, 0 ));          dstPoints.push_back( IEVisionPoint2f( inset, 0 ));
srcPoints.push_back( IEVisionPoint2f( w - 1, 0 ));      dstPoints.push_back( IEVisionPoint2f( w - 1 - inset, 0 ));
srcPoints.push_back( IEVisionPoint2f( w - 1, h - 1 ));  dstPoints.push_back( IEVisionPoint2f( w - 1, h - 1 ));
srcPoints.push_back( IEVisionPoint2f( 0, h - 1 ));      dstPoints.push_back( IEVisionPoint2f( 0, h - 1 ));
hmat := IEVisionLib().createMath().findHomography( srcPoints, dstPoints, ievREGULAR );

ImageEnView1.IEBitmap.AssignIEVisionImage( ImageEnView1.IEBitmap.GetIEVisionImage().warpPerspective( hmat, IEVisionSize( w, h ), ievLINEAR, ievBORDER_CONSTANT, IEVisionScalar( 0, 0, 0, 0 ), False ));
ImageEnView1.Update();

  

See Also

◼detect
◼findHomography
◼MatrixToIEVisionMatrix
◼Warp
◼PerspectiveDraw
◼ProjectDraw