Class DocumentEnhancer

API for document enhancement.

*

  • Required licence feature(s): DocumentScanner, ImageProcessing.

Example

Since the class is backed by native resources and implements AsyncDisposable it's highly recommended to use the await using syntax when an instance is created to ensure the resource is disposed automatically:

await using instance = await DocumentEnhancer.create(...);

Alternatively, one can explicitly call dispose method to release the native resource. If neither is used, the resource will be released when the instance is garbage collected which is not recommended.

Implements

  • AsyncDisposable

Methods

  • Returns Promise<void>

  • As the instance is backed by a native resource, it should be disposed when it is no longer needed. This method will release the native resource. As a recommended alternative since the class implements AsyncDisposable one can use 'await using' syntax to ensure the resource is disposed of automatically. If neither is used, the resource will be released when the instance is garbage collected which is not recommended.

    Returns Promise<void>

    A promise that resolves when the instance is disposed.

  • Straightens the document effectively straightening its edges and text.

    Parameters

    • image: ImageRef

      The image of the document to straighten.

    • parameters: DocumentStraighteningParameters = ...

      The parameters to use for straightening.

    • priorCornersNormalized: Point[] = []

      If it is known where the document corners (e.g. from a prior detection), those can be provided here.

      • The enhancer may take them into account to locate the document more accurately.
      • As part of the straightening process, it may be necessary to detect the document corners.
      • That's why providing them here can speed up the process (given the corners are already available).
      • Corners must be provided in the clockwise order: top-left, top-right, bottom-right, bottom-left.
      • The coordinates must be normalized to the range [0, 1] relative to the image dimensions.
      • For x coordinates, 0 corresponds to the left edge of the image and 1 to the right edge. For y coordinates, 0 corresponds to the top edge of the image and 1 to the bottom edge.
      • Note, that when a coordinate is normalized, correct formula for x coordinate is: x_normalized = x_pixel / (image_width - 1), and for y coordinate is: y_normalized = y_pixel / (image_height - 1).

    Returns Promise<DocumentStraighteningResult>

    The detection result.

  • Check if the specified straightening mode is available (i.e. required assets are present).

    Parameters

    Returns Promise<boolean>

    True if the straightening mode is available, false otherwise.