Tesseract and Portuguese: eng gets 9 accents in 10 wrong
92%
of accents right with -l por
One flag: 9.5% to 92.2%
Proofread pages from 15 Portuguese books, printed 1854 to 1945:
| Model | Accents right | Words right |
|---|---|---|
-l eng, the default |
9.5% | 85.2% |
-l por |
92.2% | 95.4% |
97.8% of letters right with eng, accents aside
14.8% of words wrong with eng
eng reads the letters. It drops almost every mark, and it reads ç as g more often than as c.
What eng does to Portuguese words
Real words from these scans. Each time, por read it right:
| Printed | eng read | Times |
|---|---|---|
| não | nao | 100 |
| são | sao | 26 |
| já | ja | 20 |
| tão | tao | 17 |
| estão | estio | 10 |
não became nao on 28 of 30 pages. A search for não never finds nao.
Install por, then pass -l por
-
Debian or Ubuntu:
sudo apt install tesseract-ocr-por -
macOS:
brew install tesseract-lang, all languages - Check:
tesseract --list-langsshows por
This writes page.txt:
tesseract page.png page -l por
In Python:
import pytesseract
print(pytesseract.image_to_string("page.png", lang="por"))
One por model covers Brazil and Portugal.
tessdata_best helps a little, eng hurts
Each against plain por, which took 0.8 seconds a page:
| Setting | Accents right | Sec a page |
|---|---|---|
| por from tessdata_best | 94.3% | 1.9 |
-l por+eng |
89.9% | 1.2 |
-l eng+por |
89.8% | 1.3 |
| script/Latin, for all Latin-alphabet languages | 89.7% | 1.4 |
Adding eng cost 32 or 33 accents, in either order. Use por alone on Portuguese pages.
One catch: old print writes the crase as á (á Lua). Plain por printed today's à instead, 30 times.
How I tested it
- Pages: pt.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, 2 pages a book. Pages with notes, poems or tables were skipped.
- A page also had to match its scan: Tesseract had to find 80% of its letters. 2 pages failed and were skipped.
- 30 pages, 56,087 letters, 1,360 of them with an accent (or ç).
- Each scan is the wiki's page image: 10 at 1,920 px, 8 at 1,280 px, 12 at 960 px.
- Accents right: accented letters read right, in order. Words right: proofread words read right, accents and all, in order.
- Running heads and page numbers are not in the proofread text, so extra text costs nothing.
- por+eng and eng+por gave different text on 9 of 30 pages, but almost the same score.
- Tesseract 5.5.4, one thread. Models from tessdata_fast 4.1.0, the files Homebrew installs, and tessdata_best 4.1.0.
Our Actor: set Language to Portuguese
Our Apify Actor reads scans with the same por file. Its Language input starts at English. On these 30 scans, live build 0.1.44:
8.3% of accents right, left at English
82.9% set to Portuguese
Test build 0.1.52 keeps 4 more pages in reading order and gets 89.3% set to Portuguese. One two-column page still comes out partly out of order. It is not the live build yet.
What I did not test
- Phone photos, faxes, and scans under 960 px wide.
- Books printed before 1850.
- Handwriting. See this test.
- Other languages. French has its own test.
- Windows and Linux. One Mac.
Sources
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
Does Tesseract read Portuguese?
Yes, with the por model. On 30 proofread book scans it read 92.2% of accented letters right. The default eng read 9.5%.
Why does Tesseract drop ã and ç?
Usually it runs with eng, the default. On these scans eng read ã as a 227 times and ç as g 170 times. Pass -l por.
Is there a Brazilian Portuguese model?
No. Tesseract has one por model for Brazil and Portugal. Its tessdata_best version read 94.3% of accents right here, at 1.9 seconds a page.