-
Notifications
You must be signed in to change notification settings - Fork 0
Performance
OCR quality and speed depend far more on the input image than on any flag.
- Resolution: aim for ~300 DPI equivalent. Text glyphs should be ≥ 20 px tall. Upscale tiny screenshots; downscale huge photos (Tesseract is slow on 12 MP).
- Binarise / contrast: high-contrast black text on white works best. Leptonica's internal Otsu thresholding handles most cases, but pre-processing (grayscale, contrast boost, deskew) helps a lot.
- Crop to the text region — less background = faster and more accurate.
This library converts the bitmap to 8-bit grayscale before handing it to Tesseract, which is smaller and faster across JNI than RGBA.
The default PSM_AUTO (3) analyses full-page layout. If you already know the shape
of your input, a tighter mode is faster and more reliable:
| Input | PSM |
|---|---|
| Full document / mixed layout | 3 (auto) |
| One paragraph / uniform block | 6 |
| A single line (receipts, labels) | 7 |
| A single word | 8 |
| A single character | 10 |
ocr.initialize(context, "eng", TesseractConfig(pageSegMode = 7))For numeric fields, IDs, or codes, a whitelist cuts errors dramatically:
TesseractConfig(whitelistChars = "0123456789")tessdata_fast (Free default) is the fastest LSTM model. tessdata_best
(Pro default) is more accurate but slower and larger. Match the pack to your
accuracy budget — see Languages.
The Free build is single-threaded (no OpenMP). On large images this leaves cores idle. Tesseract Pro ships with OpenMP enabled, which parallelises recognition across cores for a meaningful speed-up on big inputs.
Native code built in debug is 10–50× slower (unoptimised). Always benchmark a
release build — this AAR is compiled with -O3.
Rough guide on a modern arm64 device, single line of text, tessdata_fast:
~100–400 ms per recognize. Full pages and tessdata_best are proportionally
slower. result.processingTimeMs reports the actual time per call.