Skip to main content

Lightweight PP-OCR runtime – ONNX only, no OpenCV, no heavy frameworks

Project description

ppocr-lite

A lightweight PaddlePaddle-OCR runtime for images like screenshots.

Dependency Role
numpy All numerical computation
Pillow Image I/O and resize
onnxruntime Model inference
scipy (optional) Faster connected-component labelling

No OpenCV, deep-learning framework or utility libraries.


Install

pip install ppocr-lite        # CPU
pip install ppocr-lite[gpu]   # GPU (uses onnxruntime-gpu)
pip install ppocr-lite[fast]  # + scipy for faster CC labelling

Models (PP-OCRv5 mobile det/rec + v2 direction cls) can be auto-downloaded to ~/.cache/ppocr_lite/ on first use, or manually downloaded and configured.

Automatically downloaded models come from RapidOCR and are downloaded from huggingface (see here for details).

To manually download models see their huggingface - you'll need one det.onnx (for text detection), one rec.onnx (for text recognition) and the corresponding dict.txt (the model-output-to-character mapping). The mobile (= smaller) models as shipped by OnnxOCR also work quite well.


Quick Start

from ppocr_lite import PPOCRLite

ocr_engine = PPOCRLite()

for result in ocr_engine.run("screenshot.png"):
    print(f"{result.score:.2f}  {result.text}")
    # result.box is a np.ndarray (4, 2) - top-left, top-right, bottom-right, bottom-left

Use Your Own Models

from ppocr_lite import PPOCRLite, ModelConfig
from pathlib import Path

ocr_engine = PPOCRLite(
    ModelConfig(
        det_model=Path("models/PP-OCRv5/det.onnx"),
        rec_model=Path("models/PP-OCRv5/rec.onnx"),
        dict_path=Path("models/PP-OCRv5/dict.txt"),
        cls_model=False,   # skip direction classifier
    )
)

GPU inference

ocr_engine = PPOCRLite(providers=["CUDAExecutionProvider", "CPUExecutionProvider"])

Manage Downloaded Models

A few utility functions are available to configure from and to where models are downloaded:

from ppocr_lite import models

models.set_cache_directory("./my-cache-dir")
models.get_cache_directory()  # -> pathlib.Path

models.list_downloaded_models() # -> list[pathlib.Path]
models.download_default_models()
models.download_model("https://huggingface.co/me/my-repo/resolve/main/my-model.onnx?download=true")

Of course you are entirely free to not use the built-in model management functionality and instead do everything yourself – just configure your engine on initialization as described above.


Design Notes

This project is very similar to the excellent RapidOCR, but more lightweight. Notably, it does not depend on OpenCV (which weighs around 200MB) and uses numpy-based alternatives instead. This does not hurt performance much, at least in my humble tests.

Please be aware that many of those numpy-based alternatives are only really feasible because this project assumes non-distorted input images (screenshots, clean document scans, …). I have not tested it, but I'd assume it doesn't work nearly as well on inputs like perspective-distorted real-world photographs.

What's different here?

  • Detection post-processing – contour finding is replaced with scipy ndimage.label (or a numpy fallback). The minimum-area rectangle is simplified under the assumption of non-perspective distorted input. Polygon offset ("unclip") is done analytically using the area/perimeter ratio and a per-vertex outward push — accurate enough for near-rectangular screenshot text.

  • Resize – PIL BILINEAR instead of cv2.resize. The two are numerically equivalent for the precision required by OCR.

  • Crop – axis-aligned bounding-rect crop instead of a perspective warp. Screenshot text is always axis-aligned, making this lossless.

  • No config YAML, no omegaconf – plain Python dataclasses.

Limitations vs. full PaddleOCR

  • No perspective correction
  • Direction classifier is only a 0°/180° binary; no 90°/270° support.

License

This project is GPL-3.0-or-later licensed. Note that the licenses of models (self-brought or auto-downloaded) will likely differ; refer to their creators for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ppocr_lite-0.2.1.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ppocr_lite-0.2.1-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file ppocr_lite-0.2.1.tar.gz.

File metadata

  • Download URL: ppocr_lite-0.2.1.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ppocr_lite-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fc640204796c19baa495c25d149a622490c9eaa6a4f42dc7efe4ca6c77a79653
MD5 957b7f1e958f4aad87bd940169331190
BLAKE2b-256 6caea33e09cbc779c4096634be9b41fd92e151d7de198f6a0eedba0df8ff27bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for ppocr_lite-0.2.1.tar.gz:

Publisher: python-publish.yml on mityax/ppocr_lite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ppocr_lite-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ppocr_lite-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ppocr_lite-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ac4fcb714f23da4b652a53058bb29e021f95ea8bc18788716736d79ea144e23
MD5 aae4f3adf98b9a7ec583c3f13db42bbc
BLAKE2b-256 100e44b8da58f35a25285ecc8e7525751d7544cfb553d26b1a3847248c6f4c70

See more details on using hashes here.

Provenance

The following attestation bundles were made for ppocr_lite-0.2.1-py3-none-any.whl:

Publisher: python-publish.yml on mityax/ppocr_lite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page