Skip to main content

ncnn-ocr

Production-ready Python OCR built on PaddleOCR PP-OCR Mobile models running on Tencent NCNN.

Standalone, publishable to PyPI, and independent of Qefro.

Features

  • Fast CPU inference — NCNN-backed det + cls + rec pipeline (same engine as PaddleOCR-ncnn-CPP)
  • PP-OCRv5 multilingual — Tamil, Arabic, Devanagari, Latin, Korean, Cyrillic, and more
  • PP-OCRv6 profilesv6_tiny, v6_small, v6_medium
  • Simple APIrecognize(), recognize_text(), batch()
  • Auto model download — pulls weights from developerabu/pp-OCRv5-6-ncnn on first use
  • Arabic post-processing — optional visual-order → logical-order fix

Install

From source (requires native deps)

# macOS (Homebrew)
brew install cmake opencv ncnn

# Debian/Ubuntu
sudo apt install cmake libopencv-dev libomp-dev

# Build ncnn if not packaged (see https://github.com/Tencent/ncnn)
export NCNN_DIR=$HOME/.local/ncnn   # optional, CMake searches common paths

pip install .

Python dependencies only (no extension)

Pure-Python modules import without the _ncnn_ocr extension; OCR() raises a clear error until the native module is built.

Quick start

from ncnn_ocr import OCR

ocr = OCR(lang="ta")
text = ocr.recognize_text("page.png")
print(text)

lines = ocr.recognize("page.png")
for line in lines:
    print(line.text, line.confidence, line.box)

One-shot helpers:

from ncnn_ocr import recognize_text

print(recognize_text("scan.jpg", lang="en"))

Supported languages (PP-OCRv5)

Code Script / language
en English
ta, te Tamil, Telugu
hi, mr, ne Devanagari
ar, fa, ur Arabic
ko, th, el Korean, Thai, Greek
ru, uk, bg Cyrillic / Slavic
de, fr, es, latin Latin
ch, zh Chinese (generic v5 rec)
from ncnn_ocr import supported_langs
print(supported_langs())

PP-OCRv6

ocr = OCR(lang="en", profile="v6_tiny")
text = ocr.recognize_text("page.png")

Profiles: v6_tiny, v6_small, v6_medium.

Environment variables

Variable Default Description
NCNN_OCR_MODEL_DIR ~/.cache/ncnn-ocr/models Local model cache
NCNN_OCR_HF_REPO developerabu/pp-OCRv5-6-ncnn HuggingFace model repo

Build layout

py-ocr-ncnn/
├── src/ncnn_ocr/       # Python package
├── native/
│   ├── bindings.cpp    # pybind11 wrapper
│   └── paddleocr/      # vendored NCNN OCR engine (Apache-2.0)
├── CMakeLists.txt
└── pyproject.toml

Models

On first run, recognition models and keys are downloaded from HuggingFace. Shared PP-OCRv5 detection and angle-classifier weights are fetched from HuggingFace when available, otherwise from the PaddleOCR-ncnn-CPP v0.3.0 archive.

Development

python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
PYTHONPATH=src pytest -q

Release to PyPI

Event Workflow What happens
Push to main / PR ci.yml Tests + builds wheels (artifacts only, no PyPI)
Push tag v* release.yml Tests + builds wheels + publishes to PyPI

Pushing a version tag triggers .github/workflows/release.yml, which:

  1. Runs unit tests
  2. Builds Linux (x86_64) and macOS (arm64) wheels plus an sdist
  3. Runs an integration OCR smoke test on each wheel
  4. Publishes all artifacts to PyPI

One-time PyPI setup

  1. Create a PyPI API token at pypi.org/manage/account/token scoped to ncnn-ocr
  2. Add it as a GitHub secret:
  3. Create GitHub environment pypi (Settings → Environments) — used by the release workflow

Cut a release

git tag v0.1.0
git push origin v0.1.0

The workflow reads the tag (v0.1.0 → version 0.1.0) and uploads:

  • ncnn_ocr-*-cp312-cp312-linux_x86_64.whl
  • ncnn_ocr-*-cp312-cp312-macosx_*_arm64.whl
  • ncnn_ocr-*.tar.gz

Manual publish (fallback)

bash scripts/build_wheel.sh
python -m twine upload dist/*

Requires TWINE_USERNAME=__token__ and TWINE_PASSWORD set to a PyPI API token.

License

Apache-2.0 — see LICENSE. The vendored PaddleOCR-ncnn-CPP sources retain their original license.

Credits

Download files

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

Source Distribution

ncnn_ocr-0.1.0.tar.gz (253.2 kB view details)

Uploaded Source

Built Distributions

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

ncnn_ocr-0.1.0-cp312-cp312-manylinux_2_39_x86_64.whl (68.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

ncnn_ocr-0.1.0-cp312-cp312-macosx_14_0_arm64.whl (173.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

File details

Details for the file ncnn_ocr-0.1.0.tar.gz.

File metadata

  • Download URL: ncnn_ocr-0.1.0.tar.gz
  • Upload date:
  • Size: 253.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for ncnn_ocr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 68b99ddb3c9f38da7a0aa85f3946ab62d5906819d83f65d828f8fbc0dec366df
MD5 80ce469d1d0d7ec666e634cd2fa287c1
BLAKE2b-256 ef82d86b8ccf064dada156ee3d340161dcd6415318c5f587032fcc1060d2b429

See more details on using hashes here.

File details

Details for the file ncnn_ocr-0.1.0-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for ncnn_ocr-0.1.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 005485d95b681a8a8ae8f02be8b1926819aae4e7dd7610b8848b9a142d05ae6d
MD5 8bf2467026340db4b46991caa55908d3
BLAKE2b-256 f3a3b83f13ef9e7005046a1e4c9f1d4c1d8257778fd72a99a44b93a212d426fa

See more details on using hashes here.

File details

Details for the file ncnn_ocr-0.1.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for ncnn_ocr-0.1.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a8efae1d2897e8b6ecef910d6d06167e8fbea938723130e51560ad3c6d4163e8
MD5 7a795437e6029f378906fe46ffe0e925
BLAKE2b-256 479271ebdf5c0c6a4f2ec5e2c4a495bacadff43636605a6d514e262659f72388

See more details on using hashes here.

Supported by

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