Skip to content
Image docs0.3

OCR Setup

Latest stable Based on Image release 0.3.0

The OCR module adapts Tess4J/Tesseract to ImmutableImage. Adding the Maven artifact supplies Java integration, not the native engine or language data.

On macOS:

brew install tesseract tesseract-lang

On Ubuntu or Debian:

sudo apt-get install tesseract-ocr tesseract-ocr-eng

Install every requested language. Verify that tesseract —list-langs includes the values passed to OcrOptions. Configure the data path explicitly when the deployment layout does not match Tesseract defaults.

Add the OCR module, load an ImmutableImage, and call extractText with explicit language and page-segmentation options. The default engine creates a fresh Tess4J instance for each call. This avoids sharing mutable engine state, but OCR remains CPU- and native-resource-intensive; bound concurrency and request time.

  • Normal unit tests keep native OCR disabled.
  • Enable host-native checks with -Docr.enabled=true.
  • Enable container checks with -Docr.container.enabled=true when Docker is available.

Run native and container OCR checks sequentially. Keep a small fixture with known text and assert normalized content rather than layout-sensitive whitespace.

Continue with the Ktor OCR workshop or Spring Boot OCR workshop.