Note: This document describes the setup for recognizing characters from a known font. It works especially well when the characters follow a logic that can be auto-generated.
For a more general tutorial, see two tutorials by Dan Vanderkam here and there.
- Generate some text using the chars you want (in my case, a hexdump-like
format, for paperkey):
cat /dev/urandom | hexdump -e '"%_ad:" 22/1 " %02X" " " 3/1 "%02X" "\n"' | head -n 1000 | sed 's/^\([0-9][0-9][0-9]\).*:/\1:/' > train.txt
- Generate the training data (here with high degradations as it's so
restricted):
ocropus-linegen -t train.txt -e hi -f OCR-A.ttf
- Generate the model:
ocropus-rtrain -o model linegen/*/*.png
- Binarize:
ocropus-nlbin input.jpg -o input
- Segment interesting parts:
ocropus-gpageseg input/*.bin.png
- Perform recognition:
ocropus-rpred -n -m model-SOMETHING.pyrnn.gz input/*/*.bin.png
- Put everything together:
ocropus-hocr input/*.bin.png -o result.html