DEV Community

Two scans, one OCR fingerprint, 0.15% vs 8.98% text-layer errors

You open a scanned PDF, drag-select a line, and the text highlights. So there is a text layer. Can you trust it, or should you OCR the page again?

A tempting shortcut is to look at the file's structure first. On two real scanned pages, the structure gave the same answer for both, while their text-layer error rates were roughly 60 times apart (8.98 divided by 0.15).

Everything below comes from two pages, one run, one Apple-silicon Mac, so read it as "on these samples", not as a rule for scans in general.

The two pages

Page G is page 16 of the 1921 edition of "Psycho-Analysis and the War Neuroses" (Ferenczi, Abraham, Simmel, Jones, preface by Freud), an Internet Archive item marked Public Domain Mark 1.0. Its reference text is 2,697 characters, proofread against the page image by one person and not checked by anyone else.

Page B is the top half of page 2 of the 1986 "Simplified Characters Table" (National Language Commission), also an Internet Archive item under Public Domain Mark 1.0. The reference is a 557-character passage, proofread line by line against the page image.

Both files carry a hidden text layer that Internet Archive generated with Tesseract.

What the four signals read

Four things were read from each file: the font name, the share of characters drawn in invisible render mode, whether a page image covers the whole page, and the Creator and Producer fields. Labels: measured means it was run on these files.

Signal Page G Page B Label
Font GlyphLessFont only GlyphLessFont only measured
Characters in invisible render mode 100% 100% measured
Page image covers the page 1.00, JPEG 2000 plus a JBIG2 mask 1.00, same encodings measured
Creator / Producer Internet Archive Internet Archive on the original; the split copy used here reads pypdf measured

The first three rows are identical, and all three together point to a layer added by OCR.

The fourth row is the weak one. Once a page is split out or re-saved, those fields can be dropped or overwritten, and the split copy of page B shows exactly that. Treat it as a hint, not evidence.

What the error rates say

Character error rate here is edit distance divided by reference length, so an extra, a missing and a wrong character each count 1.

Text layer already in the file Tesseract, re-run macOS built-in recognition, re-run RapidOCR, re-run
Page G, 2,697 characters 4 errors, 0.15% 7, 0.26% 8, 0.30% 208, 7.71%
Page B, 557 characters 50 errors, 8.98% not tested 5, 0.90% 13, 2.33%

Label: measured, single run.

Tesseract on page B is not tested because only the English language pack was installed. The 7.71% for RapidOCR is that version on this one page, where it missed whole lines. It is not a verdict on the project.

Same fingerprint, opposite outcome. On page G the layer beat every re-run. On page B it lost to both re-runs that were tested, and the 50 errors cluster around quotation marks, enumeration commas and rare characters.

Re-OCR is not automatically better either, and the engine you re-run with changes the result: RapidOCR on page G is the 7.71% case.

What to do with the signals

The signals can tell you who made the layer. For quality, one option is to take a paragraph of about 500 characters, compare it by eye with the page image, and count mistakes. If the count is high, re-run a second engine on the same paragraph and compare the two counts before committing to either.

For a page that mixes native text with images that contain text, ImgIng, at https://imging.ai/ , is a browser tool that merges the native text and the text recognized inside images into one output.

One boundary matters here: when the page image is a JPEG 2000 or JBIG2 scan, as both pages here are, ImgIng cannot recognize it at the moment, so such files should be rendered to ordinary images first.

Not tested

  • Scans that were never touched by Tesseract, such as layers made by other OCR engines. Their font names and render modes may differ.
  • Handwriting, phone photos, long documents. Both pages are clean publication scans, and each is a single page.
  • Any Windows tool, and Tesseract with a Chinese language pack.
  • Whether the faint page image on page G is why re-OCR did worse there. That is a guess; no control was run.
Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.