Options
All
  • Public
  • Public/Protected
  • All
Menu

Class OCREngine

Low-level synchronous API for performing OCR.

Instances are constructed using createOCREngine.

Hierarchy

  • OCREngine

Index

Constructors

  • new OCREngine(tessLib: any, progressChannel?: MessagePort): OCREngine
  • Initialize the OCREngine.

    Use createOCREngine rather than calling this directly.

    Parameters

    • tessLib: any

      Emscripten entry point for the compiled WebAssembly module.

    • Optional progressChannel: MessagePort

      Channel used to report progress updates when OCREngine is run on a background thread

    Returns OCREngine

Methods

  • clearImage(): void
  • Clear the current image and text recognition results.

    This will clear the loaded image data internally, but keep the text recognition model loaded.

    At present there is no way to shrink WebAssembly memory, so this will not return the memory used by the image to the OS/browser. To release memory, the OCREngine instance needs to be destroyed via destroy.

    Returns void

  • destroy(): void
  • Shut down the OCR engine and free up resources.

    Returns void

  • Perform layout analysis on the current image, if not already done, and return bounding boxes for a given unit of text.

    This operation is relatively cheap compared to text recognition, so can provide much faster results if only the location of lines/words etc. on the page is required, not the text content. This operation can also be performed before a text recognition model is loaded.

    This method may return a different number/positions of words on a line compared to getTextBoxes due to the simpler analysis. After full OCR has been performed by getTextBoxes or getText, this method should return the same results.

    Parameters

    Returns BoxItem[]

  • Perform layout analysis and text recognition on the current image, if not already done, and return the page text in hOCR format.

    A text recognition model must be loaded with loadModel before this is called.

    Parameters

    Returns string

  • Perform layout analysis and text recognition on the current image, if not already done, and return the page text as a string.

    A text recognition model must be loaded with loadModel before this is called.

    Parameters

    Returns string

  • Perform layout analysis and text recognition on the current image, if not already done, and return bounding boxes and text content for a given unit of text.

    A text recognition model must be loaded with loadModel before this is called.

    Parameters

    Returns TextItem[]

  • getVariable(name: string): string
  • Get the value, represented as a string, of a Tesseract configuration variable.

    See setVariable for available variables.

    Parameters

    • name: string

    Returns string

  • loadImage(image: ImageBitmap | ImageData): void
  • Load a document image for processing by subsequent operations.

    This is a cheap operation as expensive processing is deferred until bounding boxes or text content is requested.

    Parameters

    • image: ImageBitmap | ImageData

    Returns void

  • loadModel(model: Uint8Array | ArrayBuffer): void
  • Load a trained text recognition model.

    Parameters

    • model: Uint8Array | ArrayBuffer

    Returns void

  • setVariable(name: string, value: string): void

Generated using TypeDoc