This project provides a FastAPI-based API for evaluating the performance of multiple OCR engines (Tesseract, Nanonets, and EasyOCR) on images, particularly for Scandinavian medical records. It calculates various metrics such as character accuracy, word accuracy, sequence accuracy, edit distance score, and BLEU score.
ocr_evaluation_project/
├── ocr_evaluation/
│ ├── __init__.py
│ ├── models/
│ │ ├── ocr_metrics.py
│ ├── evaluators/
│ │ ├── base_evaluator.py
│ │ ├── tesseract_evaluator.py
│ │ ├── nanonets_evaluator.py
│ │ ├── easyocr_evaluator.py
│ ├── utils/
│ │ ├── image_processing.py
│ │ ├── text_processing.py
│ │ ├── metrics_calculation.py
│ ├── api/
│ │ ├── main.py
│ │ ├── responses.py
├── README.md
├── requirements.txt
├── setup.py
-
Clone the repository:
git clone <repository-url> cd ocr_evaluation_project
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Install the package:
pip install -e .
Run the FastAPI server:
uvicorn ocr_evaluation.api.main:app --host 0.0.0.0 --port 8000Access the API documentation at http://localhost:8000/docs.
- POST /ocr/tesseract: Evaluate images using Tesseract OCR.
- POST /ocr/nanonets: Evaluate images using Nanonets OCR.
- POST /ocr/easyocr: Evaluate images using EasyOCR.
Each endpoint accepts a list of images and corresponding ground truth texts, returning metrics including character accuracy, word accuracy, and composite score.
See requirements.txt for a complete list of dependencies. Key dependencies include:
- OpenCV
- Pytesseract
- EasyOCR
- Transformers
- FastAPI
- Torch
- Levenshtein
uvicorn api.main:app --host 0.0.0.0 --port 8080
then send a curl request as
curl -X POST "http://localhost:8080/ocr/evaluate_csv" -F "csv_file=@data/ocr_data.csv" {"detail":"400: Image not found: /images/CD3428B3-FB1B-48FD-A6BD-AD6500A37BA9_page3_det27_breathing.png"}(ocr_venv) administrator@vlad:~/Desktop/LLM_STUFF/OCR_Models/project$ curl -X POST "http://localhost:8080/ocr/evaluate_csv" -F "csv_file=@data/ocr_data.csv"