Skip to content
Edit this page

OCR

KurdPDF reads pages and lines that have no usable text layer with Tesseract. This file says when that happens, how to set it up, and how accurate it was in our measurements (spike S-6). Central Kurdish OCR is supported with the accuracy measured below and no more.

Setup

  1. Install Tesseract 5: apt install tesseract-ocr (Debian/Ubuntu), dnf install tesseract (Fedora), brew install tesseract (macOS).
  2. Get a Central Kurdish model (ckb.traineddata or another ckb*.traineddata). KurdPDF does not ship one.
  3. Put it in ~/.local/share/kurdpdf/tessdata (the user data folder), or name a folder with --tessdata DIR, the KURDPDF_TESSDATA environment variable, or tessdata in the [ocr] config section.

--ocr-lang auto picks a Kurdish model first (ckb, then other ckb* and kur_ara). With none, it falls back to ara or fas from the system models and warns ocr-model: those read Sorani much worse (see below). With no Tesseract or no model at all, KurdPDF warns ocr-unavailable once, with install steps, and continues without OCR.

Page images go to a private temporary folder that is removed after each call. Nothing is sent over the network.

When OCR runs

--ocr What is read by OCR
auto (default for convert) scanned pages (no text, images cover at least half the page); pages where resolution failed or coverage is low; lines with many unresolved glyphs
always every page with text or images
never (default for inspect) nothing

Line rule (auto): a line is weak when more than 10 % of its visible glyphs are unresolved and at least 2 are. Weak lines are cropped from one 300 dpi render and read one by one (Tesseract page segmentation mode 7); the page method becomes mixed. When weak lines are more than half of the lines with glyphs, the whole page is read instead (method ocr).

Whole pages are read with segmentation mode 3, rendered at the resolution of the largest image on the page (clamped to 100–400 dpi), or at 300 dpi when there is none.

OCR text goes into the resolved layer and through the same orthography (text) layer and block detection as other pages. The raw layer keeps whatever text the PDF had. Page.ocr (JSON ocr) records the provider and version, model, mean confidence, number of lines, number of regions (0 for a whole page), the preprocessing chain and Tesseract's raw output. Brackets on right-to-left lines are swapped to their logical form, and bidi marks Tesseract adds are dropped.

Warnings: ocr-unavailable, ocr-model, ocr-failed, ocr-empty, low-ocr-confidence (mean confidence below 0.6).

Preprocessing

--ocr-preprocess takes a comma-separated chain, or none. Steps: gray, invert-dark (inverts pages with a dark background), upscale (to 300 dpi), denoise (median filter), autocontrast, binarize (Otsu), border (white margin). The default is gray,invert-dark,border, the chain that measured best overall in S-6: binarizing helped clean renders but hurt degraded scans, and upscaling hurt degraded scans and did nothing on real ones.

Measured accuracy (S-6)

Measured on 2026-11-21 with Tesseract 5.5.0 and a community ckb LSTM model (best and fast variants). CER and WER are computed by kurdpdf.metrics after NFC and whitespace normalization.

Set A: pages with exact truth

8 pages from two Sorani books with correct text layers (a school textbook and a literature book), rendered as images in two variants: clean (300 dpi) and degraded "scan" (150 dpi, blur, slight skew, noise, JPEG quality 40). The truth is the resolved text layer. Lines are aligned before scoring.

Whole-page OCR, no preprocessing, by model:

Model Line CER Line CER, brackets swapped WER
ckb (best) 0.079 0.072 0.22
ckb (fast) 0.080 0.073 0.22
ckb+ara 0.082 0.079 0.23
fas (best) 0.16 0.17 0.50
ara 0.42 0.42 0.79

With ckb, word recall was 0.79 and precision 0.81.

Preprocessing chains, ckb, CER with brackets swapped:

Chain Clean Scan
none 0.073 0.072
gray 0.062–0.064 0.072
border 0.062–0.064 0.071
upscale 0.062–0.064 0.082
binarize (Otsu) 0.056 (WER 0.197) 0.079
upscale + binarize 0.056 —
median + binarize — 0.096
upscale + median + binarize — 0.085

Line OCR (the mixed path), default chain: 155 lines of at least 5 glyphs, all of them resolved, were cropped from 6 of the same pages and read one by one. The character-weighted CER was 0.049 (textbook 0.071, literature book 0.029). The median line CER was 0.014, and 39 % of lines were read without an error.

Set B: real scans

Seven pages from real scanned books (96–300 dpi) have no truth text, so they were scored by the share of words found in the Sorani word list. As a ceiling, correct text scores 0.74–0.89 on the same measure (set A truth pages).

Page Scan dpi ckb, border
prose, 96 dpi 96 0.82
prose 1 300 0.83
prose 2 300 0.86
prose 3 300 0.88
prose 4 300 0.76
prose 5 300 0.83
classical poetry 150 0.43 (fas: 0.46)

Means over the pages by chain: border 0.773, upscale 0.771, none or gray 0.770, upscale + binarize 0.767, binarize 0.763. fas scored 0.61–0.62. On prose, ckb OCR is close to the ceiling of correct text.

Limits

  • Classical poetry with diacritics and unusual layout reads badly (0.43 on set B).
  • Expect about 7 wrong characters in 100 on a page, and about 1 wrong word in 5.
  • Digits are sometimes split or merged, and brackets with nothing between them can be lost.
  • Low-resolution scans (below 150 dpi) and photos of pages were not measured beyond the one 96 dpi page.
  • Non-Kurdish models (ara, fas) are only a fallback; their output needs checking.
  • Columns, tables and footnotes come from Tesseract's page segmentation and are not checked against the PDF layout.