| data | ||
| models | ||
| .gitignore | ||
| coral_ocr.c | ||
| coral_ocr.h | ||
| LICENSE | ||
| Makefile | ||
| ocrcoral.c | ||
| ocrcoralpdf.c | ||
| pdf_render.cpp | ||
| pdf_render.h | ||
| README.md | ||
| ss_boxes_sample.png | ||
| stb_image.h | ||
| stb_image_write.h | ||
coral-ocr
OCR that runs entirely on a Google Coral Edge TPU. Two small command-line tools:
ocrcoral— read the text in an image and print it.ocrcoralpdf— turn a scanned PDF into a searchable PDF (the original pages with an invisible, selectable text layer on top).
It locates text with a neural line-detector and reads it with a neural character-recognizer — both running 100% on the TPU.
How it works
A two-stage, fully-convolutional pipeline — two int8 models, both on the Edge TPU:
- Detector — a segmentation model finds the text-line boxes on the page.
- Recognizer — a CenterNet-style model detects every character in each line.
A small dictionary pass then fixes spacing and word boundaries. No LSTM and no CPU inference in the hot path, which is what lets the whole thing fit and run on the TPU.
Build
Needs the Coral Edge TPU runtime (libedgetpu) and the TensorFlow-Lite C library
(expected at ~/coral-c), plus libhpdf and libpoppler-cpp for the PDF tool:
sudo apt install libhpdf-dev libpoppler-cpp-dev
make
sudo make install # optional: puts ocrcoral / ocrcoralpdf on your PATH
Usage
ocrcoral — image → text
ocrcoral [OPTIONS] IMAGE
ocrcoral photo.png # print the recognized text
ocrcoral --nopostproc photo.png # raw output, no spacing/spelling cleanup
ocrcoral --boxes photo.png # write photo_boxes.png showing WHERE text was found
ocrcoral --boxes out.png photo.png # ...to a specific file
ocrcoralpdf — scanned PDF → searchable PDF
ocrcoralpdf [OPTIONS] IN.pdf OUT.pdf
ocrcoralpdf scan.pdf searchable.pdf
It renders each page, OCRs it on the TPU, and writes a new PDF containing the original page images plus an invisible, selectable text layer — with a live progress bar. Rendering runs in parallel and overlaps the OCR.
Common options (both tools): --nopostproc (raw recognizer output),
--version, --help. --boxes is ocrcoral-only.
Models & data
models/ holds the two int8 Edge-TPU models (line detector + character
recognizer) and data/count_1w.txt is the word-frequency list used for spacing
correction. Paths are resolved relative to the binary by default; override with
CORALOCR_HOME, CORALOCR_DET, CORALOCR_REC, or CORALOCR_FREQ.
Notes
- Everything runs on the Edge TPU — one device, one process at a time.
- The recognizer covers letters, digits, and common punctuation; other symbols and non-Latin scripts aren't recognized.
- Correction is conservative: it fixes spacing and word boundaries but leaves numbers, codes, and names alone.
