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.
Install the host engine
Section titled “Install the host engine”On macOS:
brew install tesseract tesseract-langOn Ubuntu or Debian:
sudo apt-get install tesseract-ocr tesseract-ocr-engInstall 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.
Use the smallest API
Section titled “Use the smallest API”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.
Test in layers
Section titled “Test in layers”- Normal unit tests keep native OCR disabled.
- Enable host-native checks with
-Docr.enabled=true. - Enable container checks with
-Docr.container.enabled=truewhen 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.