Skip to main content

CoPaw OCR Skill

Python Version License OCR Engine

基于 RapidOCR 的高性能本地 OCR 技能,支持文件识别、截图识别、Base64 识别


✨ 特性

  • 🚀 高性能 - 速度快 3-5 倍,基于 ONNX Runtime
  • 🎯 高准确率 - 99.61% 平均置信度,工业级质量
  • 📦 轻量级 - 仅 14.9MB,比 PaddleOCR 小 10 倍
  • 🔗 智能路由 - 自动识别输入类型(文件/Base64/截图)
  • 💰 完全免费 - 无 API Key,无任何费用
  • 🔧 易于使用 - 一行代码搞定

📦 安装

方式 1:从 PyPI 安装(推荐)

pip install copaw-ocr-skill

方式 2:从 GitHub 安装

pip install git+https://github.com/lcq225/copaw-ocr-skill.git

方式 3:本地安装

git clone https://github.com/lcq225/copaw-ocr-skill.git
cd copaw-ocr-skill
pip install -e .

🚀 快速开始

基础用法

from copaw_ocr import recognize, extract_text

# 文件识别
result = recognize('image.png')
print(result['full_text'])

# 截图识别
result = recognize()
print(result['full_text'])

# 提取纯文本
text = extract_text('image.png')
print(text)

高级用法

from copaw_ocr import OCRSkill

# 创建 OCR 实例
skill = OCRSkill()

# 文件识别
result = skill.recognize_from_file('image.png')

# Base64 识别
result = skill.recognize_from_base64(base64_data)

# 截图识别
result = skill.recognize_from_screenshot()

📖 使用示例

示例 1:批量处理

from pathlib import Path
from copaw_ocr import OCRSkill

skill = OCRSkill()

for img_path in Path('images').glob('*.png'):
    result = skill.recognize_from_file(str(img_path))
    if result.get('success'):
        print(f"{img_path.name}: {result['text_count']} 个文本块")

示例 2:置信度过滤

from copaw_ocr import recognize

result = recognize('image.png')

# 过滤高置信度文本
high_conf_texts = [
    t['text'] for t in result['texts']
    if t['confidence'] >= 0.95
]

print(high_conf_texts)

示例 3:与 Windows-MCP 集成

from windows_mcp import WindowsMCP
from copaw_ocr import recognize

with WindowsMCP() as mcp:
    # 点击按钮
    mcp.Click(loc=[500, 300])

    # 截图识别
    result = recognize()

    if result.get('success'):
        print(result['full_text'])

更多示例请参考 examples/ 目录。


📊 返回结果格式

{
    "success": True,
    "text_count": 212,
    "full_text": "任务管理器\n进程\n运行新任务...",
    "texts": [
        {
            "text": "任务管理器",
            "confidence": 0.9999,
            "bbox": [[x1, y1], [x2, y2], [x3, y3], [x4, y4]]
        },
        ...
    ],
    "source": "file",
    "elapse": {
        "detection": 2.24,
        "recognition": 0.87,
        "total": 4.32
    }
}

🔧 配置

初始化参数

from copaw_ocr import OCRSkill

skill = OCRSkill(use_gpu=False)
参数 类型 默认值 说明
use_gpu bool False 是否使用 GPU(暂不支持)

⚠️ 注意事项

  1. 首次使用 - 会自动下载模型(约 50MB),模型位置:C:\Users\<用户名>\.rapidocr\
  2. 图片要求 - 支持 PNG、JPG、JPEG、BMP 格式,建议分辨率 1000px × 1000px 以上
  3. 性能优化 - 批量处理时复用 OCRSkill 实例,避免重复初始化
  4. GPU 支持 - 当前版本仅支持 CPU,GPU 支持计划在后续版本推出

🐛 故障排查

问题 1:RapidOCR 未安装

错误信息:

RuntimeError: RapidOCR 未安装,请运行:pip install rapidocr_onnxruntime

解决方案:

pip install rapidocr_onnxruntime

问题 2:模型下载失败

解决方案:

  1. 检查网络连接
  2. 使用国内镜像:
    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple rapidocr_onnxruntime
    

问题 3:截图失败

错误信息:

PIL ImageGrab 不可用

解决方案:

pip install Pillow

📚 文档


🤝 贡献

欢迎贡献代码、报告问题或提出建议!

  1. Fork 本仓库
  2. 创建功能分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 创建 Pull Request

📄 许可证

本项目采用 MIT 许可证 - 详见 LICENSE 文件。


🙏 致谢


📞 联系方式


🎊 星标支持

如果这个项目对你有帮助,请给我一个 ⭐️!


版本: 1.0.0 最后更新: 2026-04-11

Metadata

Release files for copaw-ocr-skill 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for copaw-ocr-skill 1.0.0
File Size Uploaded
copaw_ocr_skill-1.0.0.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for copaw-ocr-skill 1.0.0
File Interpreter ABI Platform
copaw_ocr_skill-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / copaw_ocr_skill-1.0.0.tar.gz

Download URL copaw_ocr_skill-1.0.0.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ed1133fc087b5420571368fb8cdcc67e16561360cba8ac8128ef2eb54cb2dd7f
BLAKE2b-256 checksum
How to use checksums
9d4a077df0295966b7a625edf05638a3265127d4f43a012a25bed4856573b460
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / copaw_ocr_skill-1.0.0-py3-none-any.whl

Download URL copaw_ocr_skill-1.0.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf06f10bd5d38072749a1f4acb65b66cffee9a5265a1d487f0e9bae9d5eaa7f1
BLAKE2b-256 checksum
How to use checksums
f22a65dd453223babc34861e8fc9934c3a4a1dbda46049966872c14292d86dd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page