廖工AI设计实战出品 — easyocr + tesseract 双引擎OCR系统,15条预处理链含实测基准数据。从截图、海报、手机拍照、文档中优雅提取文字。
By LiaoGong AI — Dual-engine OCR combining easyocr + tesseract with 15 benchmarked preprocessing chains. Extract text from screenshots, posters, phone photos, and documents.
| 引擎 | 擅长 | 短板 |
|---|---|---|
| easyocr | 中文截图、海报、复杂排版 | 速度慢,首次下载100MB模型 |
| tesseract | 英文文档、白底黑字、极快 | 中文复杂排版效果差 |
一个工具,两个引擎,自动选择最优方案。
pip install liaogong-ocr
# 或开发模式
git clone https://github.com/jnbno1163/liaogong-ocr.git
cd liaogong-ocr
pip install -e .安装后直接使用命令:
liaogong-ocr your_image.jpggit clone https://github.com/jnbno1163/liaogong-ocr.git
cd liaogong-ocr
pip install -r requirements.txt
python -m liaogong_ocr.engine your_image.jpgnpx clawhub@latest install liaogong-ocr触发词:OCR this image / 图片转文字 / OCR识别 / 提取图片文字
# 自动选择引擎
liaogong-ocr poster.jpg
# 中文复杂场景用 easyocr
liaogong-ocr -e easyocr screenshot.png
# 英文文档快速 OCR
liaogong-ocr -e tesseract document.png
# 手机拍照优化模式(87%数字准确率)
liaogong-ocr -p phone photo.jpg
# 保存到文件
liaogong-ocr image.jpg -o result.txt
# 显示详细信息
liaogong-ocr image.jpg --verbosefrom liaogong_ocr import OCREngine
engine = OCREngine()
result = engine.process("poster.jpg", engine="easyocr")
print(result["text"])
print(result["confidence"])
print(result["engine_used"])from liaogong_ocr import CHAINS, chain_cross_validate
# 应用最优手机拍照预处理链
img = CHAINS['optimal_phone'](image)
# 多链交叉验证(可靠性更高)
results = chain_cross_validate(image)安装 ClawHub 技能后,AI 助手自动识别以下触发词并调用 OCR:
OCR this image/extract text from image图片转文字/OCR识别/提取图片文字/截图转文字
手机拍屏幕数字提取,15条预处理链实测结果:
| 预处理链 | 处理方式 | 数字准确率 | 速度 |
|---|---|---|---|
| optimal_phone | 反色+灰度+对比度2.5x | 87% | 快 |
| grayscale_binary | 灰度+二值化阈值128 | 72% | 快 |
| contrast_enhance | 灰度+对比度增强2.0x | 65% | 快 |
| sharpen | 灰度+锐化滤镜 | 55% | 快 |
| clahe | CLAHE直方图均衡化 | 31% | 中 |
| adaptive_binary | 自适应二值化阈值 | 18% | 慢 |
liaogong-ocr/
├── liaogong_ocr/ # Python 包
│ ├── __init__.py # 导出 OCREngine, CHAINS, CHAIN_BENCHMARKS
│ ├── engine.py # 核心双引擎OCR
│ └── preprocess.py # 15条可组合预处理链
├── scripts/
│ ├── benchmark_chains.py # 重现基准测试
│ └── batch_ocr.py # 批量文件夹OCR
├── tests/
│ └── test_ocr_engine.py # 冒烟测试
├── examples/ # 示例图片
├── references/ # 预处理指南+基准报告
├── setup.py # pip 安装配置
└── requirements.txt
- Python 3.8+
- Tesseract 系统安装:
- Windows:
winget install tesseract-ocr - macOS:
brew install tesseract - Linux:
sudo apt install tesseract-ocr
- Windows:
- easyocr 1.7+(首次运行下载 ~100MB 模型,之后缓存本地)
廖工AI设计实战出品 · github.com/jnbno1163