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 profiles —
v6_tiny,v6_small,v6_medium - Simple API —
recognize(),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:
- Runs unit tests
- Builds Linux (
x86_64) and macOS (arm64) wheels plus an sdist - Runs an integration OCR smoke test on each wheel
- Publishes all artifacts to PyPI
One-time PyPI setup
- Create a PyPI API token at pypi.org/manage/account/token scoped to
ncnn-ocr - Add it as a GitHub secret:
- Go to github.com/qefro-ai/py-ocr-ncnn/settings/secrets/actions
- New repository secret
- Name:
PYPI_API_TOKEN - Value: your
pypi-...token
- 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.whlncnn_ocr-*-cp312-cp312-macosx_*_arm64.whlncnn_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
- Avafly/PaddleOCR-ncnn-CPP — NCNN OCR engine
- PaddleOCR — PP-OCR models
- Tencent NCNN — inference framework
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68b99ddb3c9f38da7a0aa85f3946ab62d5906819d83f65d828f8fbc0dec366df
|
|
| MD5 |
80ce469d1d0d7ec666e634cd2fa287c1
|
|
| BLAKE2b-256 |
ef82d86b8ccf064dada156ee3d340161dcd6415318c5f587032fcc1060d2b429
|
File details
Details for the file ncnn_ocr-0.1.0-cp312-cp312-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: ncnn_ocr-0.1.0-cp312-cp312-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 68.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
005485d95b681a8a8ae8f02be8b1926819aae4e7dd7610b8848b9a142d05ae6d
|
|
| MD5 |
8bf2467026340db4b46991caa55908d3
|
|
| BLAKE2b-256 |
f3a3b83f13ef9e7005046a1e4c9f1d4c1d8257778fd72a99a44b93a212d426fa
|
File details
Details for the file ncnn_ocr-0.1.0-cp312-cp312-macosx_14_0_arm64.whl.
File metadata
- Download URL: ncnn_ocr-0.1.0-cp312-cp312-macosx_14_0_arm64.whl
- Upload date:
- Size: 173.4 kB
- Tags: CPython 3.12, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8efae1d2897e8b6ecef910d6d06167e8fbea938723130e51560ad3c6d4163e8
|
|
| MD5 |
7a795437e6029f378906fe46ffe0e925
|
|
| BLAKE2b-256 |
479271ebdf5c0c6a4f2ec5e2c4a495bacadff43636605a6d514e262659f72388
|