Skip to main content

本地轻量级OCR识别工具

Project description

本地轻量级OCR识别工具

基于 RapidOCR + ONNX Runtime

🚀 极速识别 (~1秒/张) | 💻 低资源占用 (<300MB) | 🔒 完全离线

Python >= 3.8 | Windows/Linux/Mac


项目简介

这是一个轻量级的本地OCR文字识别工具,基于RapidOCR实现,采用ONNX Runtime推理框架。相比PaddleOCR,速度提升4-5倍,内存占用降低200MB+,同时保持99%+的识别准确率。

  • ✅ 完全离线运行,保护隐私
  • ✅ 低资源占用(内存<300MB)
  • ✅ 识别速度快(~1秒/张)
  • ✅ 高准确率(99.5%中文,99%+英文)
  • ✅ 支持批量处理
  • ✅ 多种输出格式
  • ✅ 跨平台支持(Windows/Linux/Mac)

安装

通过pip安装(推荐)

pip install rapid-ocr-tool

安装后使用:

所有平台 (推荐使用简短命令):

ocr image 图片路径.jpg
ocr batch 文件夹路径

完整命令 (向后兼容):

ocr-tool image 图片路径.jpg
ocr-tool batch 文件夹路径

Windows (如果命令不可用):

python -m main image 图片路径.jpg
python -m main batch 文件夹路径

从源码安装

# 克隆仓库
git clone https://github.com/yourusername/ocr-tool.git
cd ocr-tool

# 安装
pip install -e .

使用方法

单张图片识别

# 简短命令(推荐)
ocr image 图片路径.jpg

# 完整命令
ocr-tool image 图片路径.jpg

# Windows备选方式
python -m main image 图片路径.jpg

批量处理文件夹

# 简短命令(推荐)
ocr batch 文件夹路径

# 完整命令
ocr-tool batch 文件夹路径

# Windows备选方式
python -m main batch 文件夹路径

指定输出格式

# 输出为文本
ocr image 图片.jpg --format txt

# 输出为JSON(包含坐标信息)
ocr image 图片.jpg --format json

# 输出为Markdown
ocr image 图片.jpg --format md

高级选项

# 保存到文件
ocr image 图片.jpg --output result.txt

# 指定识别语言(ch/en)
ocr image 图片.jpg --lang ch

# 显示详细信息
ocr image 图片.jpg --verbose

支持的图片格式

  • PNG
  • JPG/JPEG
  • BMP
  • TIFF

性能指标

指标 数值
单张识别速度 ~1秒(CPU)
内存占用 <300MB
中文准确率 99.5%
英文准确率 99%+
支持分辨率 最高4096px

项目结构

ocr/
├── src/
│   ├── ocr_engine.py       # OCR引擎核心
│   ├── image_processor.py  # 图像预处理
│   ├── batch_processor.py  # 批量处理
│   └── output_formatter.py # 输出格式化
├── models/                  # 模型文件(自动下载)
├── output/                  # 默认输出目录
├── config/
│   └── config.yaml         # 配置文件
├── main.py                 # 主入口
├── requirements.txt        # 依赖列表
└── README.md              # 使用文档

📚 文档

常见问题

1. 首次运行慢?

首次运行会自动下载模型文件(约12MB),请耐心等待。

2. 识别结果不准确?

  • 确保图片清晰,分辨率足够
  • 尝试调整图片对比度
  • 对于复杂背景,先进行图像预处理

3. 批量处理中断?

已处理的结果会自动保存,可以重新运行继续处理。

技术栈

  • OCR引擎: RapidOCR (基于PaddleOCR优化)
  • 推理框架: ONNX Runtime
  • 模型: PP-OCRv3 轻量级模型 (12.3MB)
  • 图像处理: OpenCV + Pillow
  • CLI框架: Click + Rich

项目结构

ocr/
├── src/
│   ├── __init__.py           # 模块初始化
│   ├── ocr_engine.py         # OCR引擎核心
│   ├── image_processor.py    # 图像预处理
│   ├── batch_processor.py    # 批量处理
│   └── output_formatter.py   # 输出格式化
├── config/
│   └── config.yaml           # 配置文件
├── models/                    # 模型文件(自动下载)
├── output/                    # 默认输出目录
├── main.py                   # CLI入口
├── examples.py               # 使用示例
├── test_install.py           # 安装测试
├── requirements.txt          # 依赖列表
├── QUICKSTART.md            # 快速开始指南
└── README.md                # 项目文档

开源协议

MIT License


致谢

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

rapid_ocr_tool-1.1.0.tar.gz (44.7 kB view details)

Uploaded Source

Built Distribution

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

rapid_ocr_tool-1.1.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file rapid_ocr_tool-1.1.0.tar.gz.

File metadata

  • Download URL: rapid_ocr_tool-1.1.0.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for rapid_ocr_tool-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b33f839e2f04e9ed25b7669227821938acac37e37ef4375641acd4e08ab9b1de
MD5 d24545c0854beb45f4c6bc8c0c563924
BLAKE2b-256 e021a6052763a17df2367d2bae5d7ca24e0d57410d57364c1747127d7e7a48af

See more details on using hashes here.

File details

Details for the file rapid_ocr_tool-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: rapid_ocr_tool-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for rapid_ocr_tool-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 daec886900bd66519c5c99acd6460337d200fc3898aa2749107e7b087d23dfeb
MD5 31c6a5575c7ff2d8f6e313bde34cbabb
BLAKE2b-256 381cc02133afaac5de5cbd833e7def84649f0d599bfd9903fbbc3f3daa96bbcd

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