Access RapidOCR Documentation
mainThe official, comprehensive documentation for RapidOCR, including detailed guides, API references, and advanced usage instructions, is hosted at the following URL:
https://rapidai.github.io/RapidOCRDocsrepository·main·Indexed 27 days ago
https://github.com/rapidai/rapidocrAn open-source, high-speed OCR tool designed for multi-platform and multi-language deployment. RapidOCR converts PaddleOCR models into ONNX format for efficient inference across various devices. It supports multiple inference engines including ONNX Runtime (CPU/GPU), NVIDIA TensorRT, PaddlePaddle, Intel OpenVINO, PyTorch, and MNN. The library provides a Python package installable via pip, as well as Docker environments for development and deployment.
The official, comprehensive documentation for RapidOCR, including detailed guides, API references, and advanced usage instructions, is hosted at the following URL:
https://rapidai.github.io/RapidOCRDocsRapidOCR uses pre-commit to automatically run code formatters like black and autoflake before commits. This ensures code style consistency.
pre-commit within your activated virtual environment in the python directory.Commands:
# Inside the 'python' directory with virtualenv activated
pip install pre-commit
# Return to the repository root to install hooks
cd ..
pre-commit installTo manually run the checks on all files before committing, run this from the repository root:
pre-commit run --all-filespip install pre-commit
cd ..
pre-commit install
pre-commit run --all-filesInstall the rapidocr package along with onnxruntime using pip to enable OCR capabilities.
pip install rapidocr onnxruntimeDocker environments are available for various inference engines. You can build and test using ONNX Runtime (CPU) or use other engines like tensorrt, paddle, openvino, pytorch, or mnn.
# Build and test with ONNX Runtime (CPU)
make build-onnxruntime-cpu
make test-onnxruntime-cpu
# Or use any engine: onnxruntime-gpu, tensorrt, paddle, openvino, pytorch, mnn
make build-tensorrt
make shell-tensorrtNew tests should be placed in python/tests/ with the naming convention test_*.py. Use pytest and place any required test assets (like images) in python/tests/test_files/.
When writing tests, ensure they reliably verify changes and avoid depending on undocumented external services (use mocks where necessary).
# tests/test_xxx.py
import pytest
from pathlib import Path
root_dir = Path(__file__).resolve().parent.parent
tests_dir = root_dir / "tests" / "test_files"
@pytest.fixture()
def engine():
from rapidocr import RapidOCR
return RapidOCR()
def test_your_new_feature(engine):
img_path = tests_dir / "ch_en_num.jpg"
result = engine(img_path)
assert result is not None
# more assertions...Tests should be executed from the python directory. You can run all tests, specific files, or check coverage.
Commands:
# Run all tests
pytest tests/ -v
# Run specific test files
pytest tests/test_input.py -v
pytest tests/test_det_cls_rec.py -v
# Check test coverage (requires pytest-cov)
pytest tests/ -v --cov=rapidocrpytest tests/ -vIf you prefer not to use the Makefile, you can use docker compose targeting the docker/docker-compose.yaml file.
docker compose -f docker/docker-compose.yaml build <service>docker compose -f docker/docker-compose.yaml run --rm <service> pytest tests/ -vdocker compose -f docker/docker-compose.yaml run --rm <service> pytest tests/test_engine.py -k "<engine_name>" -vdocker compose -f docker/docker-compose.yaml run --rm <service> bashNote: Replace <service> with the engine name, e.g., onnxruntime-cpu.
When adding new features or fixing bugs, you must include corresponding unit tests.
python/tests/ with the naming convention test_*.py.python/tests/test_files/.pytest.Example Test Structure:
# tests/test_xxx.py
import pytest
from pathlib import Path
root_dir = Path(__file__).resolve().parent.parent
tests_dir = root_dir / "tests" / "test_files"
@pytest.fixture()
def engine():
from rapidocr import RapidOCR
return RapidOCR()
def test_your_new_feature(engine):
img_path = tests_dir / "ch_en_num.jpg"
result = engine(img_path)
assert result is not None
# Add more assertions...import pytest
from pathlib import Path
root_dir = Path(__file__).resolve().parent.parent
tests_dir = root_dir / "tests" / "test_files"
@pytest.fixture()
def engine():
from rapidocr import RapidOCR
return RapidOCR()
def test_your_new_feature(engine):
img_path = tests_dir / "ch_en_num.jpg"
result = engine(img_path)
assert result is not NoneTo contribute to the Python portion of RapidOCR, clone the repository and configure a virtual environment within the python directory.
Prerequisites:
Setup Steps:
git clone https://github.com/RapidAI/RapidOCR.git
cd RapidOCRcd pythonvenv or conda):# Using venv
python -m venv .venv
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\activate # Windows
# Using conda
conda create -n rapidocr python=3.10
conda activate rapidocrpytest for testing. It is recommended to install the current package in editable mode (-e) to ensure local changes take effect immediately:pip install -r requirements.txt
pip install pytest
pip install -e .git clone https://github.com/RapidAI/RapidOCR.git
cd RapidOCR
cd python
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install pytest
pip install -e .To install the RapidOCR Python package along with the required ONNX Runtime, use the following command:
pip install rapidocr onnxruntime