Tesseract Thai Language: Getting OCR Spacing Right

Illustrated infographic summarizing: Tesseract Thai Language

By Greg Nowak. Last updated 2026-10-19.

Thai OCR can produce text that looks almost right while leaving awkward gaps, missing marks, or scrambled reading order. If your team is extracting text from scanned documents, those errors can turn a promising automation into another manual checking job.

Start with the correct Tesseract language model, match the settings to the page layout, and compare the output against the original. The preserve_interword_spaces option remains useful to test, but it needs a clearer explanation than the original short command example gave it.

Use the Thai language code: tha

For the standard Thai language model, use -l tha. The language file is tha.traineddata, as listed in Tesseract’s official model documentation. Replace the original example’s -l Thai with -l tha.

First, check the installed engine and available languages:

tesseract --version
tesseract --list-langs

If tha is missing, install the Thai language data using your platform’s package manager or place a compatible tha.traineddata file in its configured tessdata directory. The Tesseract command manual documents --tessdata-dir for specifying a different location.

For a full page, a straightforward starting command is:

tesseract image.png outfile -l tha --oem 1 --psm 3

This writes the recognised text to outfile.txt. The input filename is an example; substitute your own image.

What does preserve_interword_spaces actually do?

The original article suggested enabling preserve_interword_spaces=1 to address odd spacing. Keep it as an experiment, rather than treating it as a universal Thai OCR fix.

Tesseract’s command-line guide demonstrates the option preserving wider gaps in a table of contents. It preserves detected interword spacing in text output; it does not promise to remove unwanted spaces or repair Thai word boundaries.

For a cropped, uniform block of text, compare these two runs:

tesseract image.png baseline -l tha --oem 1 --psm 6
tesseract image.png preserved -l tha --oem 1 --psm 6 -c preserve_interword_spaces=1

Compare baseline.txt and preserved.txt against the same image. Keeping the other settings identical makes it easier to judge whether preserving spaces helps your documents.

Thai generally uses spaces between phrases rather than individual words, as explained in the W3C’s draft Thai Script Resources. I would avoid a blanket cleanup rule that deletes every space: legitimate phrase breaks, English names, and reference numbers need attention too.

Match the layout setting to the document

A setting that works for a paragraph may fail on a complete form. Tesseract’s quality guidance recommends choosing a segmentation mode suited to the image region.

Input layout Starting setting Check in the output
Complete document page --psm 3 Reading order and missing sections
One uniform text block --psm 6 Line breaks and unexpected gaps
One cropped text line --psm 7 Characters and marks retained
Scattered labels or short snippets --psm 11 Text found; reading order needs review
Use these as starting points for comparison, then keep the setting that performs best on representative documents.

For forms, consider processing clearly defined regions separately. A customer address and an item table may need different handling. Decide how those regions map to your destination system before building a batch process.

Improve the image before adding more settings

Check whether the original scan is sharp, straight, and evenly lit. Tesseract recommends images of at least 300 dpi and warns that skew can damage line recognition. Rescanning a poor original may be more productive than repeatedly changing OCR parameters.

Leave a small margin around cropped text. Compare any cleaned image with the original, especially around small marks above and below Thai characters. Aggressive noise removal can make a page look cleaner while removing details you need recognised. Change one preprocessing step at a time so you can tell which change helped.

Choose models by testing your own pages

The official model families include tessdata_fast and tessdata_best. The former prioritises speed; the latter trades processing speed for potentially better recognition. Both require the LSTM engine, selected with --oem 1, according to the official model documentation.

Test both if correction work is expensive. Record processing time alongside the errors a reviewer actually has to fix. For mixed Thai and English documents, also test -l tha+eng, with both language models installed. More languages should earn their place through better results on your sample.

Make the pilot useful to the business

Choose a small sample covering the documents your team really receives: clear scans, difficult scans, different templates, and mixed language pages. Ask a fluent Thai reader to check the text against the images.

Set acceptance criteria around the task. Searchable archives and automatic entry of invoice amounts have different consequences when recognition fails. Track incorrect characters, missing content, field accuracy, and review time separately. A document can look readable while still containing an incorrect reference number.

Keep the source image, raw OCR output, model identity, and command settings together. That gives operations staff and agency developers something reproducible when a new template performs poorly. Agree who reviews exceptions before connecting the output to a live workflow.

If you are assessing Thai OCR for an archive, document import, or internal process, talk to Greg about a focused pilot. Bring representative documents and explain where the extracted text needs to go; that provides a practical basis for deciding what to automate and where review belongs.

Related on GrN.dk

Need help with this kind of work?

Discuss a Thai OCR pilot with Greg Get in touch with Greg.

Sources

Seneste artikler

Lad AI kundeservice hente ordrestatus fra Shopify og Shipmondo. Se, hvordan I afgrænser opgaven, kontrollerer kundens identitet og sender usikre sager videre.

Når kunden beder om indsigt, kan AI hjælpe med at samle materiale fra WordPress og Microsoft 365. Se, hvordan I holder styr på datakilder, ansvar og kontrol.

Når en ingrediens ændres, kan menukortet kræve rettelser, selv om opskriftsdatoen står stille. Sådan kan AI hjælpe med gennemgang og godkendelse i WordPress.

Når checkout fejler, skal driftspartneren have noget konkret at arbejde med. Se, hvordan AI, dmesg og journalctl kan samle sporene i en brugbar driftssag.

Brug oktober til at afprøve daglige AI-forslag til genbestilling før Black Friday. Få styr på Shopify-data, leveringstid og budget, før forslagene bliver til indkøb.

Jeg lærte serverdrift ved at ødelægge mine egne servere. Jeg søger en, der vil stå ved siden af mig, mens jeg gør det, og så gøre det selv ugen efter.

Jeg er god til at bygge og dårlig til at ringe. Her er, hvem jeg vil have ved siden af mig, hvad der er lettest at sælge, og hvordan vi deler det.

AI kan samle onboardingopgaverne før første arbejdsdag. Se, hvordan lederen godkender konkret adgang, og hvordan åbne opgaver bliver fulgt til dørs.

En AI-assistent kan svare på spørgsmål og føre kunder til booking. Her er de konkrete grænser for pris, levering, personoplysninger og kontakt med en medarbejder.

Et sikkert AI-workflow kan omsætte Meet- og Teams-transskripter til godkendte beslutninger og opgaver i Jira eller Asana – uden at slippe kontrollen.