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
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.1.tar.gz.
File metadata
- Download URL: ncnn_ocr-0.1.1.tar.gz
- Upload date:
- Size: 252.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
515ffde7cebacb35a027eb5335328df55b4203bca6e19e5b3173d836bcec3ac3
|
|
| MD5 |
cc547f45e436798c1c1d959aa3e24702
|
|
| BLAKE2b-256 |
2d5f6d855cab51689081b408f02973eba5c7d2a01231517cbd2b1a7902eb9a05
|
File details
Details for the file ncnn_ocr-0.1.1-cp312-cp312-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: ncnn_ocr-0.1.1-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 |
b821301023e69c8e00f2f299df9b5e7bff50877a568e5ae6f4981d99c669fd33
|
|
| MD5 |
624a9caff698b38a7a037a1310ade292
|
|
| BLAKE2b-256 |
8df8223456db0e46df2edd69b11da97e3b605590acb26fc12034cf719d35e382
|
File details
Details for the file ncnn_ocr-0.1.1-cp312-cp312-macosx_14_0_arm64.whl.
File metadata
- Download URL: ncnn_ocr-0.1.1-cp312-cp312-macosx_14_0_arm64.whl
- Upload date:
- Size: 174.9 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 |
3e8b14825d786db143c99000abb84047b3a20d098a78953a0bbe1d62ac14b36f
|
|
| MD5 |
68737af5a6878e246fc40127c6eed969
|
|
| BLAKE2b-256 |
4e7b0a88ec9ef69c5586c47ced0a8d2b986347f604abc388c8c84443d5739763
|