ONNX PaddleOCR
这是一个基于 ONNX 的 PaddleOCR 实现,支持文字检测和识别功能。
特性
- 支持多种语言文字识别
- 基于 ONNX,无需安装 PaddlePaddle 和 paddleocr
- 支持 GPU 加速(需要 onnxruntime-gpu)
- 轻量级部署
use-gpu
- 如果使用 GPU, 本项目使用:
onnxruntime-gpu==1.18.1 - 检查 CUDA 和 cuDNN 版本是否正确: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements
nvcc --version
安装
pip install onnx-paddleocr # pip安装
uv add onnx-paddleocr # uv安装
使用方法
命令行使用
pipx install onnx-paddleocr # pipx安装
uv tool install onnx-paddleocr # uv安装
ocr --help # 帮助信息
ocr ./test.jpg --output ./output # 示例:识别图片,输出json文件
ocr ./test.jpg # 控制台输出
ocr ./test.jpg --use-gpu # 需要安装支持的CUDA和cuDNN
Python API 使用
import cv2
from onnx_ocr import ONNXPaddleOcr, result_to_json_data, save_to_img, save_to_json
# 初始化OCR
model = ONNXPaddleOcr(
use_angle_cls=False,
use_gpu=False,
cpu_threads=16,
det_model_dir="", # 不指定默认:~/.onnx/models/ppocrv5_server/det/det.onnx
rec_model_dir="", # 不指定默认:~/.onnx/models/ppocrv5_server/rec/rec.onnx
)
# 读取图片
img = cv2.imread("./images/test.jpg")
# 执行OCR
result = model.ocr(img)
# 转为json数据
json_data = result_to_json_data(result)
save_to_img(img, result, "output")
save_to_json(json_data, "output")
模型文件
模型采用ppocrv5_server文件不会包含在安装包中,首次运行时程序会自动从 GitHub Releases 下载所需模型文件到本地用户目录下的:~/.onnx/models/ppocrv5_server
如果您希望手动下载模型,请访问以下链接:
将这些文件放置在如下目录结构中:
~/.onnx/models/
└── ppocrv5_server/
├── det/
│ └── det.onnx
└── rec/
└── rec.onnx
部分参数说明
| 参数 | 默认值 | 说明 |
|---|---|---|
| --use-angle-cls | False | 是否使用角度分类器 |
| --use-gpu | False | 是否使用 GPU |
| --det-model | ~/.onnx/models/ppocrv5_server/det/det.onnx | 检测模型路径 |
| --rec-model | ~/.onnx/models/ppocrv5_server/rec/rec.onnx | 识别模型路径 |
许可证
本项目采用 MIT 许可证。
Metadata
Release files for onnx-paddleocr 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| onnx_paddleocr-0.2.4.tar.gz | 6.5 MB | Without provenance | Details for onnx_paddleocr-0.2.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| onnx_paddleocr-0.2.4-py3-none-any.whl | Python 3 | none | any | Details for onnx_paddleocr-0.2.4-py3-none-any.whl |
Total release size: 13.1 MB
Release files / onnx_paddleocr-0.2.4.tar.gz
| Download URL | onnx_paddleocr-0.2.4.tar.gz |
|---|---|
| Size | 6.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0d950da7e629d00b359e0f9b828340e74e31f301405e4af597547c2a45d7910
|
|
BLAKE2b-256 checksum How to use checksums |
490becdc7c5c748115fd526a2023062a14ec5624f15476e9b2070df10645fe3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / onnx_paddleocr-0.2.4-py3-none-any.whl
| Download URL | onnx_paddleocr-0.2.4-py3-none-any.whl |
|---|---|
| Size | 6.6 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
504cce1e3488d4f570ac333c8824918c51ea42febc2844700fb47a7714a75a37
|
|
BLAKE2b-256 checksum How to use checksums |
995907fd379680fd04f1f01c656fd52a62b20312cf6353c5cd1692d67b24ed8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for onnx-paddleocr 0.2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.