Tools,

Tesseract Arabic OCR: which model reads your scans

84%

letters right with ara best on real scans

Get the command

The fast file misses one letter

One line from a 2018 law. The bold word is wrong:

Model Read
Proofread الباب الخامس: التدابير والمبادرات للوقاية من العنف
ara, best الباب الخامس: التدابير والمبادرات للوقاية من العنف
ara, fast الباب الخامس: التدابير والمبادرات للوقاية من العكف
eng waial) cya 4418 gi! Ss) pthread g pash sith sc pals} lal

eng has no Arabic letters, so it writes Latin ones.

best reads more than the fast file

Proofread scans from 12 books, 1902 to 2020. Letters right, of 45,772:

Model Size Right
eng 4.1 MB 0.0%
ara+eng, fast 5.5 MB 67.0%
script/Arabic 9.3 MB 73.2%
ara, fast 1.4 MB 78.3%
ara, tessdata 2.5 MB 78.8%
ara, best 12.6 MB 84.0%

The fast file is the one apt and Homebrew install. best took 1.7 times as long: 1.08 s a page against 0.64 s.

How I tested it
  • Pages: ar.wikisource scans whose text was proofread. Books printed in 1900 or later, one file per work, picked by a seeded shuffle, not by me.
  • Each page is a real scan inside a PDF, drawn at the scan's own pixels per inch. Pages were 980 to 2,444 px wide.
  • One plain tesseract run per page and model, default settings, Tesseract 5.5.4.
  • A letter counts when it is found in order. Diacritics, digits and punctuation do not count.
  • Whole words are harder: best got 62.5% of the words fully right.
  • The old engine (--oem 0) stopped with an error on every page: the tessdata ara file has no parts for it.
Each book, with best
Book Right
2018, Moroccan law on violence against women 97.2%
2018, Moroccan law on explosives 95.3%
2020, Moroccan law on simpler procedures 93.0%
1996, Moroccan constitution 91.1%
1943, al-Siddiqa bint al-Siddiq 89.6%
1932, al-Bidaya wa al-Nihaya 87.2%
1913, on Arabic punctuation 86.8%
1923, Jurji Zaydan's trip to Europe 84.4%
1923, Dhamm al-muwaswisin 78.5%
1912, a life of al-Bukhari 75.7%
1922, Kalimat wa isharat 67.6%
1902, on newspaper Arabic 51.6%

The 1902 scan shows a strip of the facing page.

Do not add eng

78.3% with -l ara

67.0% with -l ara+eng

Both use the fast files. These pages hold only 68 Latin letters in all.

Lines 50 px tall read best

I scaled each page so its text lines were one height, then read it again. Letters right with best:

Line height Right
As scanned 84.0%
20 px 55.6%
30 px 72.1%
40 px 83.0%
50 px 87.0%
60 px 86.5%
80 px 85.9%

Line height is the median line box from Tesseract's own layout, dots and all.

Install the model and run it

apt (tesseract-ocr-ara) and Homebrew (tesseract-lang) install the fast file. To get best, put it in a folder:

mkdir -p ~/tessdata
curl -L -o ~/tessdata/ara.traineddata \
  https://raw.githubusercontent.com/tesseract-ocr/tessdata_best/4.1.0/ara.traineddata
tesseract page.png page --tessdata-dir ~/tessdata -l ara

In Python, with pytesseract, scaled to 50 px lines first:

import os
import statistics

import pytesseract
from PIL import Image

CFG = "--tessdata-dir " + os.path.expanduser("~/tessdata")
img = Image.open("page.png")
d = pytesseract.image_to_data(img, lang="ara", config=CFG, output_type="dict")
h = statistics.median(
    d["height"][i]
    for i in range(len(d["level"]))
    if d["level"][i] == 4 and d["width"][i] >= 4 * d["height"][i]
)
s = 50 / h
img = img.resize((round(img.width * s), round(img.height * s)), Image.LANCZOS)
text = pytesseract.image_to_string(img, lang="ara", config=CFG)
What I did not test
  • Windows and Linux. One Mac, Tesseract 5.5.4.
  • Handwriting, manuscripts and lithographed books.
  • Persian, Urdu and Ottoman Turkish.
  • Diacritics: they are not scored here.
  • Pages with notes, tables, poetry or Quran verses.
  • Cleaning the image first, and other OCR engines.
Sources

Our Actor gets Arabic word order wrong

Our Apify Actor has the same fast ara file, but today it puts the words of each line in left to right order. On these scans it got 25.1% of the letters in order. Until that changes, use Tesseract as above.

Two ways to skip the work

Run it yourself. Our Apify Actor turns scanned PDFs into Markdown, tables included.

Try the Actor

Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.

Get one page free

Questions people ask

Which Tesseract model is best for Arabic?

ara from tessdata_best. On 44 proofread scans it got 84.0% of the letters right. The fast ara that apt and Homebrew install got 78.3%.

Why does Tesseract return nothing for Arabic?

Check -l. With -l eng it found 0 Arabic letters on 44 pages. Use -l ara alone: -l ara+eng got 67.0%.

Does Tesseract output Arabic text backwards?

No. The letters came out in reading order: the fast file got 78.3% in order, and 9.5% when read backwards.