1

I am searching a library or tool to do OCR.

Below is an example of a scan.

Needed features:

  • OCR for full page. Should detect several areas and different font sizes
  • Running on Linux (SuSE 42.3 and Ubuntu 16.04)
  • No online service. The OCR should happen without internet connection
  • Needs to be integrated into Python. Via subprocess would be ok, as library is prevered
  • Commercial software is ok.
  • Optional: Detect hand written words

enter image description here

Sad, even the bounty a gave did not help. There was only a solution based on open source software. I think there are commercial ocr engines available which have much better results - but this is only a guess.

1
+50

I would recommend using Tesseract via the pyocr library.

You will need these packages:

Here is a sample script based on the pyocr documentation:

#! /usr/bin/env python3

# https://github.com/openpaperwork/pyocr

from PIL import Image
import sys

import pyocr
import pyocr.builders

if len(sys.argv) == 1:
    sys.stderr.write("Usage: {} /path/to/image.png".format(sys.argv[0]))
image_path = sys.argv[1]

tools = pyocr.get_available_tools()
tool_to_use = None
for tool in tools:
    if tool.get_name() == 'Tesseract':
        tool_to_use = tool

if tool_to_use is None:
    sys.stderr.write("Missing dependency:")
    sys.stderr.write("apt install 'tesseract-ocr'")
    sys.exit(1)

lang = 'deu'
langs = tool_to_use.get_available_languages()
if lang not in langs:
    sys.stderr.write("Missing dependency:")
    sys.stderr.write("apt install 'tesseract-ocr-deu'")
    sys.exit(1)

txt = tool_to_use.image_to_string(
    Image.open(image_path),
    lang=lang,
    builder=pyocr.builders.TextBuilder()
)
sys.stdout.write(txt)

It takes about 9 seconds to process your example image on my laptop.

$ /usr/bin/time --output=time.log --verbose python3 do_ocr.py fAtTn.png > out.txt
$ grep 'wall clock' time.log 
    Elapsed (wall clock) time (h:mm:ss or m:ss): 0:09.11

The overhead from the Python library is probably minimal, since the time is comparable to running the tesseract command directly.

$ /usr/bin/time --output=time-tesseract.log --verbose tesseract -l 'deu' fAtTn.png fAtTn
Tesseract Open Source OCR Engine v3.04.01 with Leptonica
$ grep 'wall clock' time-tesseract.log 
    Elapsed (wall clock) time (h:mm:ss or m:ss): 0:09.54

(I am running Debian 9, not Ubuntu 16.04, but they should be comparable.)

Here is the output with extraneous newlines suppressed:

05.10.2017 IS—U: Laufkarte (ISU) Einbau HKWLSS Original Seite 1

Auftrag zum Geräteeinbau Sparte?®

Auftrag 4043400 ServicemeldungE%C%j()é?%?ä3
Techn.?latz 1030423
Straße: Nr. 63 261/10

Einbauzähler
Serialnummer ‚ SW;K;ÄÄC .................
Materialtyp ..................................
Herstellemummer' ..................................

Zählerstand HT

Zählerstand NT 6}

Bestätigung des Zählerstandes vom Geschäftspartner:

Gebrauchsfähigkeitsprüfung Hauptprüfung nach TRGI Pkt.?
Leckmenge l/h dicht O

_ €?ßäää?ä ???» .............

Anlage .....

Zugeordnete Verbrauchssrelle
Übernahme Beschriftung am Zählerplatz

Geräleplatznummer

Beschreibung Geräleplaiz

Brancizenxchlüssel ‘

weitere Wichtige Infbrmationen zur Anlage ..........................................
Datum ....... &“!äQ‘fia ........................
. 953 ,
Unterschnfl Monteur ........... ".”. . . f .........................
ÄQB€
Bearbeitungsvermerk technisch gg; ] kauflnännisch
Datmn/Signum/Slempel

Tesseract will struggle with the handwritten sections, but the typeset text is mostly intact.

  • 9 seconds is quite long these days. I am willing to buy a library to get better results. – guettli Nov 6 '17 at 11:44
  • Have you tried it on your machine? Tesseract has pretty good accuracy, but it is CPU intensive. – Nathaniel M. Beaver Nov 6 '17 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.