Service FastAPI d'extraction de tableaux depuis des images, via morphologie mathématique OpenCV.
Conçu pour tourner sur Raspberry Pi 4 (ARM64) — aucun modèle IA lourd.
| Composant | Rôle |
|---|---|
| FastAPI | API REST |
| OpenCV headless | Détection de tableau (kernels morphologiques) |
| Uvicorn | Serveur ASGI |
| Docker + Compose | Packaging & déploiement (compatible Portainer) |
# Build + start
docker compose up --build
# Test rapide
curl -X POST http://localhost:8000/extract \
-F "file=@mon_tableau.png"Body : multipart/form-data avec un champ file (image PNG/JPEG).
Réponse 200 :
{
"rows": 3,
"cols": 4,
"cells": [
[
{"x": 10, "y": 10, "width": 120, "height": 40},
...
],
...
]
}- Binarisation adaptative — robuste aux variations d'éclairage.
- Kernel horizontal (
MORPH_RECT w//30 × 1) → isole les lignes H. - Kernel vertical (
MORPH_RECT 1 × h//30) → isole les lignes V. - Fusion + dilatation → grille complète.
- Contours (
findContours RETR_TREE) → bounding boxes des cellules. - Clustering par centre Y/X → attribution
row/col.
Le volume Docker monte ./app dans le container.
Toute modification de app/*.py rechargée automatiquement par Uvicorn (--reload).
docker compose up # pas besoin de --build à chaque changement.
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI + endpoint /extract
│ └── processing.py # Pipeline OpenCV
├── docker/
│ └── Dockerfile
├── docker-compose.yml
├── pyproject.toml
└── README.md