AfrOCR — end-to-end document extraction for African languages (OCR/HTR, form fields, evaluation)
# afrocr
End-to-end document extraction for **African languages** (Kinyarwanda and English first): scanned forms and handwritten pages in, transcripts and structured fields out. Runs on a server (Docker + FastAPI) or in Colab, with a built-in evaluation harness so every engine choice is measured, not guessed.
*AfrOCR* — OCR for Africa. Languages are pluggable modules; Kinyarwanda and English are first, the continent is the roadmap.
## The problem
The target documents are hard for classic OCR in two different ways:
- **Filled forms** — printed Kinyarwanda templates (land registry, health, finance…) with handwritten values: names, IDs, dates, free-text explanations.
- **Handwritten pages** — cursive Kinyarwanda and English, photographed with phones (shadows, perspective, uneven lighting).
Measured on 18 ground-truth pairs with Tesseract (the strongest classic-OCR baseline available — there is **no Kinyarwanda model** for any classic OCR engine):
| engine | category | language | docs | mean CER | mean WER |
|--------|----------|----------|-----:|---------:|---------:|
| tesseract | forms | kin | 12 | 48.4% | 80.0% |
| tesseract | handwriting | eng | 3 | 80.1% | 133.9% |
| tesseract | handwriting | kin | 3 | 82.7% | 125.9% |
Half the characters wrong on forms, unusable on handwriting. This is why the pipeline is built around **vision-language models** with classic OCR as a comparison baseline, and why every change is validated against the evaluation set.
## Architecture
```
ingest PDF / photo / scan -> page images (DOCX reader for ground truth)
preprocess shadow flattening, denoise, Hough deskew, Otsu binarization
route printed | handwritten | mixed form (Tesseract word-confidence signal)
languages one module per language: name, Tesseract model, orthography, repairs
engines tesseract | gemini | openai | qwen (local GPU) — pluggable
fields schema-driven key-value JSON (IFISHI 15 registered; generic fallback)
postprocess gener …