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

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.1.tar.gz (252.4 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.1-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.1-cp312-cp312-macosx_14_0_arm64.whl (174.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Hashes for ncnn_ocr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 515ffde7cebacb35a027eb5335328df55b4203bca6e19e5b3173d836bcec3ac3
MD5 cc547f45e436798c1c1d959aa3e24702
BLAKE2b-256 2d5f6d855cab51689081b408f02973eba5c7d2a01231517cbd2b1a7902eb9a05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ncnn_ocr-0.1.1-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 b821301023e69c8e00f2f299df9b5e7bff50877a568e5ae6f4981d99c669fd33
MD5 624a9caff698b38a7a037a1310ade292
BLAKE2b-256 8df8223456db0e46df2edd69b11da97e3b605590acb26fc12034cf719d35e382

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ncnn_ocr-0.1.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3e8b14825d786db143c99000abb84047b3a20d098a78953a0bbe1d62ac14b36f
MD5 68737af5a6878e246fc40127c6eed969
BLAKE2b-256 4e7b0a88ec9ef69c5586c47ced0a8d2b986347f604abc388c8c84443d5739763

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