Modules

Python API reference documentation for the OCR service modules. Auto-generated documentation covering all functions, classes, and methods used in the Tesseract and PaddleOCR REST API implementation.

API Reference

OCR Service API

This module provides a Flask API for performing OCR (Optical Character Recognition) on uploaded images.

app.api.get_paddle_ocr()

Get or initialize the global PaddleOCR instance.

app.api.health()

Health check endpoint.

Returns a 200 status code to indicate the service is running.

Example (using curl):

curl http://localhost:5000/health

Returns:

Empty response with 200 status code.

Return type:

flask.Response

app.api.index()

Perform OCR on an uploaded image.

Expects a POST request with:
  • a file field named ‘image’ (the image to process)

  • an optional form field ‘engine’ to specify the OCR engine (‘tesseract’ or ‘paddleocr’). If not provided, defaults to ‘paddleocr’.

  • an optional form field ‘lang’ to specify OCR language(s). The language code format depends on the engine: * Tesseract: ‘eng’, ‘jpn’, ‘fra’, ‘eng+fra’, ‘chi_sim’, etc. * PaddleOCR: ‘en’, ‘japan’, ‘fr’, ‘ch’, ‘korean’, etc.

File size limit: Configurable via MAX_FILE_SIZE_MB environment variable (default: 10MB).

Example (using curl):

curl -X POST -F “image=@/img.pnghttp://localhost:5000/ curl -X POST -F “image=@/img.png” -F “engine=tesseract” -F “lang=jpn” http://localhost:5000/ curl -X POST -F “image=@/img.png” -F “engine=paddleocr” -F “lang=ch” http://localhost:5000/

Returns the extracted text and detected regions in JSON format.

Returns:

  • flask.Response – JSON response containing: - text: Concatenated extracted text from all regions - regions: List of detected text regions (both engines provide bounding

    boxes) Each region contains: - bbox: Bounding box coordinates [[x1,y1], [x2,y2], [x3,y3], [x4,y4]] - text: Extracted text for this region - confidence: Confidence score (0.0 to 1.0)

  • Supported Engines

  • —————-

  • - tesseract (Fast and efficient for standard document OCR)

  • - paddleocr (Better for multi-directional and rotated text (default))

  • Supported Languages

  • ——————

  • **Tesseract** (All Tesseract language and script packs installed in the)

  • container are supported. Common examples include

    • English (eng)

    • French (fra)

    • Japanese (jpn)

    • German (deu)

    • Spanish (spa)

    • Chinese (chi_sim, chi_tra)

    • Russian (rus)

    • Arabic (ara)

    • (See Dockerfile for included Tesseract languages)

  • **PaddleOCR** (Supports 80+ languages including:) –

    • English (en)

    • Chinese Simplified (ch)

    • Japanese (japan)

    • Korean (korean)

    • French (fr)

    • German (german)

    • Spanish (es)

    • Portuguese (pt)

    • Russian (ru)

    • Arabic (ar)

  • Supported File Formats

  • ———————

  • All image formats supported by the Python Pillow library, including

    • PNG

    • JPEG/JPG

    • BMP

    • TIFF