Add EasyOCR engine for receipt image parsing

EasyOCR (deep-learning OCR) replaces Tesseract as the default engine for
receipt images. It handles phone photos, thermal paper, dot-matrix fonts,
and rotated images significantly better than Tesseract without requiring
manual preprocessing pipelines.

Key design decisions:
- OCR_ENGINE=easyocr (default) | tesseract — switchable via .env, no rebuild
- EasyOCR Reader is a module-level singleton: model loaded once per container
  start, not per receipt
- Falls back to Tesseract automatically if EasyOCR fails or returns < 20 chars
- EXIF rotation fix still applied before EasyOCR (phone photo orientation)
- Images resized to max 2000px width for speed before passing to EasyOCR
- _easyocr_to_text() groups detections into visual lines (y-overlap) and
  sorts left-to-right within each line for clean single-string output

Revert: echo "OCR_ENGINE=tesseract" >> .env && docker compose up -d agent-service

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Carlos Garcia
2026-05-21 01:22:22 -04:00
parent a736f3352b
commit 69519393c1
2 changed files with 131 additions and 1 deletions

View File

@@ -15,5 +15,9 @@ ollama==0.3.3
pdfplumber==0.11.4
Pillow==10.4.0
pytesseract==0.3.13
# EasyOCR: deep-learning OCR, better on phone photos and difficult fonts.
# Set OCR_ENGINE=tesseract in .env to use Tesseract instead.
# Note: pulls in torch (~1.5GB) — only add if disk space allows.
easyocr
python-multipart==0.0.12
docker==7.1.0