RapidOCR
A fast, offline Python OCR library with pluggable ONNX Runtime, OpenVINO, and PaddlePaddle inference backends.
Repository Health
Technical Analysis
RapidOCR converts the models behind PaddleOCR into the ONNX format so text detection, angle classification, and text recognition can run fast and fully offline across Python, C++, Java, C#, and mobile targets. The Python package wraps a three-stage pipeline (detect → classify → recognize) behind a single RapidOCR class, with each stage lazily loaded behind a thread lock so unused stages never pay their model-load cost.
Because inference is decoupled from any one runtime, the same pipeline can execute against ONNX Runtime, OpenVINO, PaddlePaddle, PyTorch, or TensorRT depending on what’s installed and what the deployment target needs — CPU-only edge devices, GPU servers, or embedded environments. Default models cover Chinese and English out of the box, with a documented model list for other languages, and results can be exported as text, JSON, or Markdown or rendered visually over the source image.
What You Get
- A
RapidOCRclass that runs the full detect → classify → recognize pipeline from a single call on an image path, URL, bytes, or numpy array - A pluggable inference-engine layer supporting ONNX Runtime, OpenVINO, PaddlePaddle, PyTorch, and TensorRT, selected via config without changing calling code
- Default Chinese/English models bundled, with additional language models resolvable and downloaded on demand via
model_resolver - Built-in result export to plain text, JSON, or Markdown, plus a
.vis()helper to render detected boxes and recognized text back onto the image - A
rapidocrCLI entry point for running OCR from the command line without writing Python
Common Use Cases
- Extracting text from scanned documents or photos in offline or air-gapped environments where cloud OCR APIs aren’t usable
- Feeding OCR output into downstream document-understanding or RAG pipelines (used by projects like Docling and Langchain-Chatchat)
- Building lightweight desktop or CLI OCR tools that need to run on CPU without a large deep-learning framework installed
- Automating text extraction from UI screenshots or game clients (used by automation projects like arknights-mower)
Under The Hood
Architecture
RapidOCR structures its pipeline as three independently loadable stages — text detection (ch_ppocr_det), angle classification (ch_ppocr_cls), and text recognition (ch_ppocr_rec) — orchestrated by the RapidOCR class in main.py, which loads each model lazily behind its own threading.Lock so a call that only needs detection never initializes the recognizer. Configuration flows through an omegaconf DictConfig parsed from config.yaml and mergeable with runtime params, and the inference-engine selection is resolved through a factory (inference_engine/base.py: get_engine()) that dynamically imports the backend module (ONNX Runtime, OpenVINO, PaddlePaddle, PyTorch, or TensorRT) named in config, keeping the pipeline logic decoupled from any single runtime.
Tech Stack
The package targets Python 3.8–4, built with setuptools and setuptools-scm for git-tag-derived dynamic versioning, and declares its runtime dependencies (pyclipper, opencv-python, numpy<3.0.0, Shapely, PyYAML, Pillow, tqdm, omegaconf, requests, colorlog) in a plain requirements.txt consumed dynamically by pyproject.toml. Inference-engine packages themselves (onnxruntime, openvino, paddlepaddle, torch, tensorrt) are treated as optional extras and imported only when their engine type is selected, keeping the base install lean; a rapidocr console script is registered via project.scripts for CLI use.
Code Quality
The tests/ directory is extensive — dedicated pytest modules cover the CLI, classifier, default config, the full det+cls+rec pipeline, per-engine config, image preprocessing, input-type handling, lazy model loading, model resolution, per-language recognition, word-box output, and output-format conversion — parametrized across engine types. A .pre-commit-config.yaml enforces formatting (black) before commits, and pipeline stages raise a custom RapidOCRError that call sites catch explicitly and log rather than letting failures pass silently.
What Makes It Unique RapidOCR’s differentiator is converting PaddleOCR’s models into ONNX once and then fanning that single model format out across five different inference backends and five different language runtimes (Python, C++, Java, C#, plus mobile/embedded targets in the monorepo), so the same lightweight, CPU-friendly models can be deployed nearly anywhere without depending on PaddlePaddle itself at inference time — a meaningfully different distribution strategy than most single-backend OCR libraries.
Used by 5 apps in this directory
headroom
AI Development · Developer Tools
Compress everything your AI agent reads — tool outputs, logs, RAG chunks, and files — before it reaches the LLM, achieving 60–95% fewer tokens with the same answers.
Khoj
AI Assistants · Knowledge Management · Productivity
A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.
Langflow
AI Agents · AI Development
Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.
Open WebUI
AI Assistants · AI Agents
The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.
otari
AI Development · Developer Tools
A self-hosted, OpenAI-compatible LLM gateway that puts one endpoint in front of 40+ providers, with virtual API keys, per-user budgets enforced before spend, and full usage tracking.