C# Class AForge.Imaging.DocumentSkewChecker

Skew angle checker for scanned documents.

The class implements document's skew checking algorithm, which is based on Hough line transformation. The algorithm is based on searching for text base lines - black line of text bottoms' followed by white line below.

The routine supposes that a white-background document is provided with black letters. The algorithm is not supposed for any type of objects, but for document images with text.

The range of angles to detect is controlled by MaxSkewToDetect property.

The filter accepts 8 bpp grayscale images for processing.

Sample usage:

// create instance of skew checker DocumentSkewChecker skewChecker = new DocumentSkewChecker( ); // get documents skew angle double angle = skewChecker.GetSkewAngle( documentImage ); // create rotation filter RotateBilinear rotationFilter = new RotateBilinear( -angle ); rotationFilter.FillColor = Color.White; // rotate image applying the filter Bitmap rotatedImage = rotationFilter.Apply( documentImage );

Initial image:

Deskewed image:

Show file Open project: holisticware-admin/MonoVersal.AForgeNET Class Usage Examples

Private Properties

Property Type Description
CollectLines void
GetMostIntensiveLines AForge.Imaging.HoughLine[]
InitHoughMap void

Public Methods

Method Description
DocumentSkewChecker ( ) : System

Initializes a new instance of the DocumentSkewChecker class.

GetSkewAngle ( Bitmap image ) : double

Get skew angle of the provided document image.

GetSkewAngle ( Bitmap image, Rectangle rect ) : double

Get skew angle of the provided document image.

GetSkewAngle ( BitmapData imageData ) : double

Get skew angle of the provided document image.

GetSkewAngle ( BitmapData imageData, Rectangle rect ) : double

Get skew angle of the provided document image.

GetSkewAngle ( UnmanagedImage image ) : double

Get skew angle of the provided document image.

GetSkewAngle ( UnmanagedImage image, Rectangle rect ) : double

Get skew angle of the provided document image.

Private Methods

Method Description
CollectLines ( short minLineIntensity ) : void
GetMostIntensiveLines ( int count ) : AForge.Imaging.HoughLine[]
InitHoughMap ( ) : void

Method Details

DocumentSkewChecker() public method

Initializes a new instance of the DocumentSkewChecker class.
public DocumentSkewChecker ( ) : System
return System

GetSkewAngle() public method

Get skew angle of the provided document image.
Unsupported pixel format of the source image.
public GetSkewAngle ( Bitmap image ) : double
image System.Drawing.Bitmap Document's image to get skew angle of.
return double

GetSkewAngle() public method

Get skew angle of the provided document image.
Unsupported pixel format of the source image.
public GetSkewAngle ( Bitmap image, Rectangle rect ) : double
image System.Drawing.Bitmap Document's image to get skew angle of.
rect System.Drawing.Rectangle Image's rectangle to process (used to exclude processing of /// regions, which are not relevant to skew detection).
return double

GetSkewAngle() public method

Get skew angle of the provided document image.
Unsupported pixel format of the source image.
public GetSkewAngle ( BitmapData imageData ) : double
imageData System.Drawing.Imaging.BitmapData Document's image data to get skew angle of.
return double

GetSkewAngle() public method

Get skew angle of the provided document image.
Unsupported pixel format of the source image.
public GetSkewAngle ( BitmapData imageData, Rectangle rect ) : double
imageData System.Drawing.Imaging.BitmapData Document's image data to get skew angle of.
rect System.Drawing.Rectangle Image's rectangle to process (used to exclude processing of /// regions, which are not relevant to skew detection).
return double

GetSkewAngle() public method

Get skew angle of the provided document image.
Unsupported pixel format of the source image.
public GetSkewAngle ( UnmanagedImage image ) : double
image UnmanagedImage Document's unmanaged image to get skew angle of.
return double

GetSkewAngle() public method

Get skew angle of the provided document image.
Unsupported pixel format of the source image.
public GetSkewAngle ( UnmanagedImage image, Rectangle rect ) : double
image UnmanagedImage Document's unmanaged image to get skew angle of.
rect System.Drawing.Rectangle Image's rectangle to process (used to exclude processing of /// regions, which are not relevant to skew detection).
return double