Skip to content

About

Tesseract model for console screens – Linux console, BIOS, GRUB – as seen by HDMI capture cards and IP-KVMs. Fine-tuned from eng, reads German umlauts. 0.4 % character errors on a real console vs. 6 % with stock models.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

console-ocr

A Tesseract model for text on computer consoles as an HDMI capture card or IP-KVM sees them: the Linux framebuffer console, BIOS/UEFI text screens, GRUB, terminal windows. It is Tesseract's English LSTM model (eng from tessdata_best) fine-tuned on generated console screens; it also reads the German letters ä ö ü Ä Ö Ü ß. Made for the OCR of slimkvm, a small IP-KVM, usable with any Tesseract 4/5 or tesseract.js.

On a real console it gets 0.4 % of the characters wrong, the stock deu+eng models 6 %; read line by line 0.1 %.

Use

File
model/console.traineddata integer model (1.5 MB), for reading
model/float/console.traineddata the same as float (11.8 MB), to train further from (START_MODEL)

Checksums: model/SHA256SUMS.

cp model/console.traineddata /usr/share/tesseract-ocr/5/tessdata/
python3 train/prepare.py screenshot.png prepared.png
tesseract prepared.png - -l console --psm 6 --oem 1
  • Prepare the picture like the training did (train/prepare.py): 2x upscaling, grayscale, inverted when mostly dark, levels, threshold – black text on white. Raw colour screenshots work, but not as well.
  • Best: cut the lines yourself and read each with --psm 7. Console lines have no gap; tesseract's own line finding (--psm 6) cuts off the dots of umlauts that touch the line above. A reader that knows the character grid gets them right (see the results).
  • The model has no dictionary: it reads characters, which suits serials, hashes and command lines.
  • -l console+eng reads proportional document text a little better, everything else a little worse.
  • tesseract.js: put console.traineddata where langPath points, createWorker("console", OEM.LSTM_ONLY).

Results

Real console: a Proxmox host's local console (1920x1080), captured with a USB HDMI capture card (raw YUYV), in four fonts – Fixed 16 (Debian's default), VGA 16, Terminus 32x16, Terminus Bold VGA 16 (not in the training) – one screen each, 19,000 characters of known text: German sentences, shell lines, look-alikes and real output of df, ls, systemctl, ip. Through H.264 at 4 Mbit/s like an IP-KVM stream (the raw capture gives nearly the same):

deu+eng console console+eng
whole screen (psm 6) 6.07 % 0.36 % 0.85 %
line by line (psm 7) 6.08 % 0.11 % 0.30 %

Shell signs 10.8 → 0.3 % wrong, letters and digits 5.0 → 0.2 %. Umlauts: 13 % wrong on the whole screen with either model, 0 % line by line with console. Left line by line: en_rj45 → en_r j45, -- → - -, . → ,, BOOT → ROOT. A small test; BIOS, GRUB and colours were not part of it.

Generated test screens (train/gen.py), in fonts that were not in the training, through H.264; character error rate of whole screens:

deu+eng console console+eng
Linux console 8.93 % 1.59 % 2.20 %
BIOS text mode 12.96 % 6.16 % 6.50 %
GRUB 9.23 % 2.24 % 2.63 %
Terminal windows 3.43 % 0.59 % 0.91 %
Documents (proportional fonts) 1.53 % 1.63 % 1.25 %
All 8.33 % 2.23 % 2.66 %
All, line by line 7.51 % 1.43 % 1.47 %
Multi-colour screens 11.80 % 5.41 % 6.12 %

Screenshots and MJPEG give nearly the same as H.264. Line by line: umlauts 55.7 → 6.7 % wrong, shell signs 24.5 → 1.9 %. The generated tests are harder than the real one: 80 BIOS fonts, small and odd fonts, coloured text. Left: capital Ö loses its dots (Ö→O 26 %), 0→O 10 %. Dark colours on black (dark blue, red) are nearly as dark as the background and get lost in the preparation, whatever the model. All numbers: results/SUMMARY.txt.

How it was made

  1. Text (train/corpus.sh): man pages (English, German), --help and error messages in a German locale, command output, logs, config files and hex dumps of a throwaway Debian VM. Addresses, MACs and SSH keys are replaced by documentation values. The text itself is not published.
  2. Lines for what is hard (train/gen.py): about a fifth of the lines on a screen are replaced by shell lines (prompts, | $ # ` @ ! { } [ ] ~), German words with umlauts (also in capitals and as file names) and tokens without words to guess from (serials, hex, look-alikes Z/2, O/0, l/1/I, S/5, B/8).
  3. Screens (train/gen.py): drawn in 131 fonts (Linux console fonts, 80 BIOS fonts, Unifont for GRUB, terminal fonts) at 640x480 to 2560x1440, plus documents in proportional fonts so the model does not forget ordinary text; about a fifth multi-coloured (16 console colours, systemd's [ OK ]/[FAILED], prompts). Each screen goes through H.264, as a screenshot or as MJPEG, is prepared like above and cut into lines with their known text. A line where the preparation lost a word is left out.
  4. Held out for testing, never trained: Terminus Bold VGA, Fixed 15, Toshiba Satellite, Verite, Phoenix BIOS, Liberation Mono, FreeSerif, Liberation Serif.
  5. Training: fine-tuned from eng (tessdata_best) with tesstrain on 101,352 lines for 142,222 iterations. The error on the training lines keeps falling, but after a while the model reads unseen fonts worse: it forgets what eng knew. So the best model up to every 20,000 iterations is measured on the unseen test fonts and the best one is taken – here the one of 81,700 iterations; the last one got 2.88 %. Because it was picked on the same test screens, its total of 2.23 % flatters a little.

Training runs

Four runs, measured on the same test screens (unseen fonts, whole screen / line by line, console):

Run What changed Lines Iterations Generated tests Real console
1 first version: stream, screenshots, MJPEG, colours 70,880 60,000 2.75 / 1.85 % –
2 + German output, shell lines, look-alikes 71,111 120,000 2.86 / 1.82 % (best state, 36,000: 2.48 / 1.62 %) –
3 same lines, stopped at 40,000 71,111 40,000 2.30 / 1.50 % 0.55 / 0.34 %
4 + documents and terminal windows against forgetting, + lines for the errors of run 3 (capital umlauts next to words without dots, 0/O, S/5); best state picked 101,352 142,222 (best: 81,700) 2.23 / 1.43 % 0.36 / 0.11 %

Run 2 showed that longer training alone makes it worse on unseen fonts. Run 4 trains longer, but with data against forgetting, and takes the best state. Against run 3 it reads umlauts (8.5 → 6.7 %), documents and Linux consoles better and makes up fewer umlauts (389 → 215); BIOS screens got slightly worse (5.87 → 6.16 %). The published model is run 4; train/run.sh is its recipe.

Rebuild

On Debian 13 with 8 cores and 8 GB RAM, about 7 hours and 25 GB of disk:

cd train
./setup.sh                                                     # packages, pinned downloads with sha256
mkdir -p ~/w/logs && nohup ./run.sh > ~/w/logs/run.log 2>&1 &  # result: ~/w/report/SUMMARY.txt and the models
./status.sh                                                    # progress

From a session that may end (ssh), run it as its own unit: sudo systemd-run --uid="$USER" --unit=ocr-train -p WorkingDirectory="$PWD" --setenv=OCR_WORK="$HOME/w" /bin/sh -c "./run.sh > $HOME/w/logs/run.log 2>&1"

corpus.sh takes its text from the machine it runs on, so a rebuild makes similar, not the same screens and an equivalent, not bit-identical model (H.264 also differs by a few pixels between runs). Two user and host names in the coloured prompts of gen.py were neutralised after the training. Each part of the data is made once (.done in its directory, tests.complete for the tests); delete that to make it again.

train/
setup.sh, corpus.sh, run.sh, status.sh setup, text, the whole run, progress
gen.py, prepare.py screens and lines; the picture preparation
evalocr.py, evallines.py, charerr.py error rate of whole screens, of single lines, per character
real/ test on a real console: show.sh puts a known text on tty1, makesets.py turns captures into test sets

License

The model is derived from eng.traineddata of tessdata_best (Apache License 2.0) and is itself under the Apache License 2.0 (LICENSE, NOTICE), like the scripts. Fonts and text were only used to draw the training pictures; none of them is part of the model or of this repository (FONTS.md). Not an official Tesseract model.

About

Tesseract model for console screens – Linux console, BIOS, GRUB – as seen by HDMI capture cards and IP-KVMs. Fine-tuned from eng, reads German umlauts. 0.4 % character errors on a real console vs. 6 % with stock models.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages