Example n.6 - Skew and Deformation

Top  Previous  Next

In this example we'll show a script that executes an usual procedure of image processing.

 

// Apply SKEW AND DEFORMATION CORRECTION on the image

// Range: -5/+5°

// Background: Black

 

LeftAngle:=ImgFindSkewBlackBorderLeft( _CurrentImage, 5.0, True);

TopAngle:=ImgFindSkewBlackBorderTop( _CurrentImage, 5.0, True);

RightAngle:=ImgFindSkewBlackBorderRight( _CurrentImage, 5.0, True);

BottomAngle:=ImgFindSkewBlackBorderBottom( _CurrentImage, 5.0, True);

 

if ((LeftAngle>=0) and (RightAngle>=0)) or

  ((LeftAngle<=0) and (RightAngle<=0)) then

begin

 if Abs(LeftAngle)>Abs(RightAngle) then HorzAngle:=LeftAngle else HorzAngle:=RightAngle;

end else HorzAngle:=0.0;

if ((TopAngle>=0) and (BottomAngle>=0)) or

  ((TopAngle<=0) and (BottomAngle<=0)) then

begin

 if Abs(TopAngle)>Abs(BottomAngle) then VertAngle:=TopAngle else VertAngle:=BottomAngle;

end else VertAngle:=0.0;

 

ImgCorrectDeformation( _CurrentImage, HorzAngle, VertAngle, True );

 

 

The above script executes the correction of skew and deformation on the current image. The first step calculates the skew of each side of the image (ImgFindSkewBlackBorder...); we are passing the current image handle (_CurrentImage) and the max skew angle we want to correct (' 5.0'); for each side we retrieve the calculated skew that we store into variables (LeftAngle, TopAngle, RightAngle and BottomAngle).

 

In the second step we calculate the horizontal and the vertical skew.

 

In the final step we use ImgCorrectDeformation for correcting image deformation;  we are passing the current image handle (_CurrentImage), the horizontal and the vertical skew (HorzAngle, VertAngle) and a boolean value indicating if new background has to be either white or black.