Optical character recognition for the Google Coral TPU.
Find a file
2026-07-27 02:17:17 -04:00
data Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
models Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
.gitignore Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
coral_ocr.c Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
coral_ocr.h Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
LICENSE Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
Makefile Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
ocrcoral.c Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
ocrcoralpdf.c Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
pdf_render.cpp Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
pdf_render.h Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
README.md Update README.md 2026-07-27 02:17:17 -04:00
ss_boxes_sample.png Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
stb_image.h Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00
stb_image_write.h Initial commit: coral-ocr — on-Edge-TPU OCR tools 2026-07-27 02:15:04 -04:00

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.

detected text regions

How it works

A two-stage, fully-convolutional pipeline — two int8 models, both on the Edge TPU:

  1. Detector — a segmentation model finds the text-line boxes on the page.
  2. 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.