Skip to main content

Straightening documents with the Linux Document Scanner

The Document Enhancer can straighten scanned documents by removing paper deformations such as creases, curl, folds, and crinkles, and correcting perspective distortion.

It supports two straightening modes:

ModeDescription
NONECrops the document based on estimated perspective distortion. Very fast.
STRAIGHTENRemoves paper deformations in addition to perspective correction.

Straightening an image

You can also straighten an image directly using the DocumentEnhancer API, providing full control over the enhancement process.

straightening document
loading...

Configuration options

The DocumentStraighteningParameters class provides the following options:

ParameterTypeDefaultDescription
straightening_modeDocumentStraighteningModeDocumentStraighteningMode.STRAIGHTENThe type of straightening to apply.
aspect_ratioslist[AspectRatio]EmptyExpected aspect ratios for the document. The closest matching ratio from the list is used.

Aspect ratios

By default, the aspect ratio of the straightened document is automatically determined from the detected document corners. If the document is significantly deformed, the estimated aspect ratio may be inaccurate.

In such cases, you can provide a list of expected aspect ratios using params.aspect_ratios to improve accuracy. Note that if you want to support both portrait and landscape orientations for a given paper format, provide both aspect ratios, for example AspectRatio(width=21.0, height=29.7) and AspectRatio(width=29.7, height=21.0) for A4.

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get free trial license