Skip to main content

ONNX PaddleOCR

Project description

ONNX PaddleOCR

这是一个基于 ONNX 的 PaddleOCR 实现,支持文字检测和识别功能。

特性

  • 支持多种语言文字识别
  • 基于 ONNX,无需安装 PaddlePaddle 和 paddleocr
  • 支持 GPU 加速(需要 onnxruntime-gpu)
  • 轻量级部署

gpu

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 许可证。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onnx_paddleocr-0.2.1.tar.gz (6.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onnx_paddleocr-0.2.1-py3-none-any.whl (6.6 MB view details)

Uploaded Python 3

File details

Details for the file onnx_paddleocr-0.2.1.tar.gz.

File metadata

  • Download URL: onnx_paddleocr-0.2.1.tar.gz
  • Upload date:
  • Size: 6.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","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}

File hashes

Hashes for onnx_paddleocr-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3d623802d55446fce845babaf58576bac22ce6acf7383aed2d83fc33e9305bfe
MD5 4d5824de50904e5aa5133a3b57e741e3
BLAKE2b-256 ddab6fa328ab8c55025240a2293d72ffc508c318e75181750c7dc1710a791710

See more details on using hashes here.

File details

Details for the file onnx_paddleocr-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: onnx_paddleocr-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","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}

File hashes

Hashes for onnx_paddleocr-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 136f3d5bc55f265224e4ff9c05dc8115abfc42ebe44dfa92b12c28ba73a0a75a
MD5 cf748243a2b6f6bb45ea537e3b978a14
BLAKE2b-256 6a02c3321e0eecc110a02df9a1be9441268e3f8ab9eacbfb5d4c9a5005cd5ca3

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 Pingdom Monitoring Sentry Error logging StatusPage Status page