Tesseract Thai OCR: which model reads your scans
83%
letters right with tha best
Without -l tha, nothing
Tesseract reads English unless you name the language:
0.0% letters right with the default eng
81.3% with -l tha
eng has no Thai letters, so not one came out right.
tha best reads the most, by a little
Proofread scans from 23 books, printed 1893 to 2021. Letters right, of 90,708:
| Model | Size | Right |
|---|---|---|
| tha+eng | 5.2 MB | 80.0% |
| tha, fast | 1.1 MB | 81.3% |
| script/Thai, best | 11.5 MB | 81.6% |
| tesseract.js 7, its tha | 1.1 MB | 82.8% |
| tha, best | 7.6 MB | 83.0% |
The hardest book, an 1893 law book scanned with a large seal behind the text, got 35.7% with tha best.
How I tested it
- Pages: th.wikisource scans whose text was proofread (level 3) or also checked by a second person (level 4). Books picked by a seeded shuffle, not by me, one file per work.
- Each page is a real scan: a DjVu file, or a PDF page that holds a full-page image. Pages were drawn at the scan's own width, up to 1920 px.
- One book was an English print with a Thai translation as its text. I left out every page whose script Tesseract did not detect as Thai, which dropped that book.
-
One plain
tesseractrun per page and model, default settings, Tesseract 5.5.4. - A letter counts when it is found in order. Only Thai letters and marks count, with ำ read as ํ and า on both sides.
-
Sauvola thresholding (
-c thresholding_method=2) made it worse: fast tha 77.9%, tha best 79.8%.
A space between every letter: the tessdata file
One printed line from a 1941 law:
| Model | Read |
|---|---|
| Proofread |
มาตรา ๑๐๕ จัตวา ผู้ใดรับหรือตกลงจะรับทรัพย์หรือ
|
| tha, fast or best |
มาตรา ๑๐ ๕ จัตวา. ผู้ใด รับพรอตกลงจะรับทรัพย์หรอ
|
| tha, tessdata |
ม า ต ร า ๑ ๐ ๕ จ ั ต ว า . ผู ้ ใด ร ั บ พ ร อ ต ก ล ง จ ะ ร
ั บ ท ร ั พ ย ์ ห ร อ
|
The tessdata repo's tha has the fast network, without its one setting. Spaces per 1,000 letters:
68.1 with the fast tha
787.8 with the tessdata tha
With -c preserve_interword_spaces=1, it matched the fast
tha on all 82 pages. script/Thai needs it too.
No model writes ำ
ำ is not in any Thai model. Tesseract writes ํ then า, which looks the same, so a search for คำ finds nothing.
683 ำ in the proofread text
0 ำ from any model
One replace joins them back, in the Python below.
Install the model and run it
apt (tesseract-ocr-tha) and Homebrew (tesseract-lang) install the fast file. To use best, put it in a folder:
mkdir -p ~/tessdata
curl -L -o ~/tessdata/tha.traineddata \
https://raw.githubusercontent.com/tesseract-ocr/tessdata_best/4.1.0/tha.traineddata
tesseract page.png page --tessdata-dir ~/tessdata -l tha
In Python, with ำ joined back:
import os
import pytesseract
TESSDATA = os.path.expanduser("~/tessdata")
text = pytesseract.image_to_string(
"page.png", lang="tha", config=f"--tessdata-dir {TESSDATA}"
)
text = text.replace("\u0e4d\u0e32", "\u0e33")
What I did not test
- Windows and Linux. One Mac, Tesseract 5.5.4.
- Handwriting, palm-leaf manuscripts and pages with tables.
- Phone photos, screenshots and signs.
- Splitting the text into words. Thai needs a word list for it.
- Other OCR engines.
Sources
Our Actor has no Thai yet
Our Apify Actor reads 10 languages, not Thai, so I did not run it on these scans.
Two ways to skip the work
Run it yourself. Our Apify Actor turns scanned PDFs into Markdown, tables included.
Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.
Questions people ask
Which Tesseract model is best for Thai?
On 82 proofread scans, tha best got 83.0% of the letters right, tesseract.js 82.8% and the fast tha 81.3%.
Why does Tesseract put a space between Thai letters?
The tha file from the tessdata repo, and script/Thai, lack one setting. Add -c preserve_interword_spaces=1, or use the fast or best tha file.
How do I add Thai to Tesseract?
Install tesseract-ocr-tha with apt, or tesseract-lang with Homebrew. Then pass -l tha. Without it, Tesseract reads English and gets no Thai letter right.