ImageEn, unit iexHelperFunctions

TIEBitmapHelper.OrbDetectAndDeskew

TIEBitmapHelper.OrbDetectAndDeskew


Declaration

function OrbDetectAndDeskew(InImage: TIEBitmap; ReferenceImage: TIEBitmap; OutImage: TIEBitmap = nil; MaxFeatures: Integer = 500; GoodMatchPercentage: Double = 0.15; HomographyMethod: TIEVisionHomographyMethod = ievRANSAC): Boolean


Description

A shortcut method that creates a TIEVisionORBFeaturesDetector object, calls findHomography to determine the homography and then uses warpPerspective to deskew the image.


Parameter Description
Self The input image to be deskewed
ReferenceImage The image to use as a reference for optimal alignment
OutImage Destination image for the result (needs to be created before calling method). If nil, then current image is updated
MaxFeatures Maximum number of points to detect. The higher the value specified the more accurate the result is likely to be
GoodMatchPercentage Percentage (0..1) of "good-match" to choose which points to take
HomographyMethod Method to compute the homography matrix

Result is true, unless an error occured. Typically errors occur because the homography matrix cannot be calculated (you should try increasing MaxFeatures).

Note:
You must add the iexHelperFunctions unit to your uses clause
You can draw the rects to a canvas using DrawRects
If attached to a TImageEnView, it will automatically call Update
Object detection requires IEVision. You will need to register it before calling the method


Method Behaviour

The following call:

ImageEnViewInput.IEBitmap.OrbDetectAndDeskew( ImageEnViewReference.IEBitmap, ImageEnViewResult.IEBitmap, UpDownMaxFeatures.Position );

Is the same as calling:

// detect matching points of the two images
orb := IEVisionLib().createORBFeaturesDetector();
orb.detect( ImageEnViewInput.IEBitmap.GetIEVisionImage(), ImageEnViewReference.IEBitmap.GetIEVisionImage(), 500 );

// find homography matrix (hmat) from matching points
hmat := IEVisionLib().createMath().findHomography(orb.getPoints1(), orb.getPoints2(), ievRANSAC);

// check homography validity
if IEVisionLib().createMath().isValidHomography(hmat) then
begin
  // adjust "scanned-form" to the same skew of "form" image
  imgres := ImageEnViewInput.IEBitmap.GetIEVisionImage().warpPerspective( hmat, IEVisionSize( ImageEnViewReference.IEBitmap.Width, ImageEnViewReference.IEBitmap.Height ));
  ImageEnViewResult.IEBitmap.AssignIEVisionImage( imgres );
  ImageEnViewResult.Update();
end;


Examples

// Skewed image is ImageEnViewInput, Reference image is ImageEnViewReference, deskewed result is shown in ImageEnViewResult
ImageEnViewInput.IEBitmap.OrbDetectAndDeskew( ImageEnViewReference.IEBitmap, ImageEnViewResult.IEBitmap );

// Deskew current image using a reference image
ImageEnViewInput.IEBitmap.OrbDetectAndDeskew( ImageEnViewReference.IEBitmap, nil );