Texterkennung mit Tesseract (Windows)

Immer mehr Haushalte entscheiden sich beim Druckerkauf für Multifunktionsgeräte, die sowohl Drucken, Scannen, Kopieren und Faxen können.

Geräte von Markenfirmen mit WLAN  sind teilweise unter 100 Euro erhältlich.

Die Scanner werden häufig zum Digitalisieren von Dokumenten oder Skripten verwendet. Allerdings liegen die Daten zunächst als Bilddatei auf dem Computer vor, die nicht mit einem Textverarbeitungsprogramm genutzt werden kann. Für den Computer sind die Daten vom Scanner schließlich Bilddaten, ganz gleich ob sie von einem Dokument oder einem Photo stammen.

Auf dem Markt sind zahlreiche Programm erhältlich, die auf den Namen „OCR“ hören (Optical Character Recognition, Optische Zeichenerkennung). Am populärsten sind wohl der „FineReader“, „ReadIris“ und „OmniPage“

Völlig kostenlos kann das Programm „Tesseract“ diese Aufgabe übernehmen. Schreibmaschinenseiten und Computerdrucke verarbeitet Tesseract mit hoher Genauigkeit, lediglich Bilder und Seiten mit mehreren Spalten bereiten dem Programm Probleme und müssen nach dem Scan und vor der Verarbeitung mit Tesseract manuell aus den für Tesseract bestimmten Bilddateien entfernt werden.

Außerdem müssen die Scans Tesseract als unkomprimierte TIFF-Dateien vorliegen. Der in Windows integrierte Scan-Assistent kann Daten standardmäßig in diesem gängigen Format speichern.

Optimal sind Auflösungen ab 300dpi – kein Problem für Scanner, die nicht älter als 15 Jahre sind. Sogar mit einer Digitalkamera photographierte Seite kann Tesseract trotz der Bildkrümmung zufriedenstellend in Text umwandeln.

Wie funktioniert das ganze?

Zuerst muß Tesseract hier heruntergeladen werden. Die Datei wird entpackt, zum Beispiel mit WinRAR oder 7Zip. Anschließend werden Sprachdateien für die jeweilige Sprache benötigt. Diese können hier heruntergeladen werden. Wer nicht lange suchen will findet die deutsche Sprachdatei hier. Die Datei ist wichtig, damit Tesseract deutsche Sonderzeichen wie das „ß“ und die Umlaute erkennt.

Das Verzeichnis in der heruntergeladenen Sprachdatei wird in das Verzeichnis von Tesseract entpackt. Nun befindet sich dort lediglich die Datei tesseract.exe, die bei einem Doppelklick zunächst nichts macht.

Tesseract wird nämlich von der Kommandozeile (auf Windows-Sprache: Eingabeaufforderung) bedient. Der gängigste Befehl zum Scannen der Datei Scan.tiff und der Ausgabe in die Textdatei Scan.txt in deutscher Sprache lautet:

tesseract.exe Scan.tiff Scan -l deu

Tesseract hängt unter Windows automatisch die Dateiendung „.txt“ an die Ausgabedatei an.

Um eine Menge gescannter Dokumente auf ein Mal umzuwandeln, werden alle TIFF-Bilder in das Tesseract-Verzeichnis kopiert und anschließend das Programm wie folgt aus der Eingabeaufforderung aufgerufen:

for %i in (*.tif) do tesseract.exe %i %i.txt -l deu

Liegen die Bilder in einem anderen Format (z.B. JPEG) vor und sollen in TIFF umgewandelt werden, so geht dies ebenfalls auf einen Rutsch mit den Tools aus der ImageMagick-Sammlung:

mogrify -brightness-contrast 10,80 -colorspace Gray -depth 8 +compress -rotate 90 -format tif *.jpg

Die Kommandos „-rotate 90“ (dreht das Bild um 90 Grad) und „-brightness-contrast 10,80“ können im Normalfall weggelassen werden. Mit „-brightness-contrast 10,80“ wird der Kontrast des Bildes verstärkt, was die Texterkennung bei einigen Aufnahmen für Tesseract leichter machen kann.

Zum Schluß werden ebenfalls in der Kommandozeile per

copy /b *.txt Gesamttext.txt

alle von Tesseract erzeugten Textdateien zur Datei Gesamttext zusammengefügt, die anschließend in Microsoft Word oder OpenOffice eingelesen und dort weiterverarbeitet werden kann. Dabei muß beachtet werden, daß der „copy“-Befehl nicht weiß, welche Textdateien neu sind. Daher sollte das jeweilige Verzeichnis vor der Benutzung von TIFF- und Text-Dateien vorhergegangener Scans gesäubert werden.

Fazit: Tesseract ist ein typisches Kommandozeilenprogramm mit der UNIX-Philosophie: „Erledige nur eine Aufgabe, und erledige sie dafür gut“. Tesseract erscheint auf den ersten Blick sehr primitiv und unflexibel, kann bei richtiger Benutzung aber schneller und besser als so manches teure GUI-Programm sein. Große Vorteile sind meines Erachtens die leichte Installation (lediglich Entpacken ist nötig), die hohe Geschwindigkeit des Programms und die praktisch unschlagbare Erkennungsgenauigkeit. Sämtliche Erkennungsfehler waren in meinem umfangreichen Test auf Druckfehler oder Bildfehler zurückzuführen. Auch mit per Digicam abphotographiertem Text war die Erkennungsgenauigkeit durchweg überzeugend. Ein weiterer Vorteil liegt in der leichten Einbindbarkeit von Tesseract in weitere Befehle. Während man bei einigen kostenlosen oder günstigen Texterkennungsprogrammen mühsam Seite für Seite öffnen und auf „Erkennung starten“ klicken muß, verarbeitet Tesseract mit einem einzigen Batch-Befehl beliebig viele Dateien ohne weitere Zuwendung vom Benutzer zu erfordern. Nachteile sind die Unfähigkeit von Tesseract, komplexe Textformatierungen zu erkennen mit mehreren Spalten pro Seite, wie sie in Zeitungen üblich sind. Solche Scans müssen manuell nachbearbeitet werden. Außerdem ist es für Benutzer ohne Erfahrung mit der Kommandozeile in Windows zu Anfang sicherlich etwas umständlicher als GUI-Programme, die zwar mehr Klickerei erfordern, dafür jedoch ohne Vorkenntnisse bedienbar sind.

2 Kommentare (+deinen hinzufügen?)

  1. Xela S.
    Apr 19, 2011 @ 00:10:04

    Ich habe tesseract gerade ausprobiert und ich bin von der Qualität der Erkennung ebenfalls überrascht.

    Allerdings habe ich bis jetzt als Vergleich nur gocr unter Ubuntu getestet, was wegen der nicht vorhandenen deutschen Sprachanpassung (soweit ich weiß…) ja sowieso im Nachteil ist.

    Antworten

  2. cool
    Mai 10, 2011 @ 19:09:35

    coooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool

    Antworten

Hinterlasse einen Kommentar