Image.OCR.Input (image_ocr v0.2.0)

Copy Markdown View Source

Normalises supported OCR inputs into a Vix.Vips.Image.t() and an associated raw pixel buffer suitable for handing to the Tesseract NIF.

Supported inputs:

Summary

Types

t()

An accepted OCR input. See the moduledoc for resolution rules.

Functions

Returns a tightly-packed 8-bit pixel buffer for image, ready to feed to the Tesseract NIF.

Loads input as a Vix.Vips.Image.t().

Types

t()

@type t() :: Vix.Vips.Image.t() | Path.t() | binary()

An accepted OCR input. See the moduledoc for resolution rules.

Functions

to_pixel_buffer(image)

@spec to_pixel_buffer(Vix.Vips.Image.t()) :: {:ok, map()} | {:error, term()}

Returns a tightly-packed 8-bit pixel buffer for image, ready to feed to the Tesseract NIF.

The image is normalised in two ways:

  • Down-cast to 8 bits per band when needed.

  • Constrained to 1 band (grayscale) or 3 bands (RGB). 4-band RGBA images are flattened against an opaque white background; 2-band images are reduced to grayscale.

Arguments

  • image is a Vix.Vips.Image.t().

Returns

  • {:ok, %{pixels: binary, width: pos_integer, height: pos_integer, bytes_per_pixel: 1 | 3, bytes_per_line: pos_integer}} on success.

  • {:error, reason} on failure.

to_vimage(image)

@spec to_vimage(t()) :: {:ok, Vix.Vips.Image.t()} | {:error, term()}

Loads input as a Vix.Vips.Image.t().

Arguments

  • input is one of the values described in the moduledoc.

Returns

  • {:ok, image} on success.

  • {:error, reason} if the input cannot be interpreted as an image.