- Notifications
You must be signed in to change notification settings - Fork382
Free Offline OCR 离线的中文文本检测+识别SDK
License
NotificationsYou must be signed in to change notification settings
myhub/tr
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
一款针对扫描文档的离线文本识别SDK,核心代码全部采用C++开发,并提供Python接口
编译环境:Ubuntu 16.04
我刚开发tr时,网上只有chineseocr、tesseract等少数开源OCR。tr发布后,又诞生了几款优秀的开源OCR。tr也基本上完成了自己的使命,会转为一个研究型项目,追求技术的先进性而不是实用性。
https://github.com/myhub/tr/tree/master/v2.8
- 采用当前流行的YOLO系列主干网络
- 加入轻量级Transformer Encoder结构提升模型根据上下文纠错的能力
- 降低对真实样本的依赖,训练集仅仅包含100多个真实样本
Install 安装:
pip install tr==2.8.2 -i https://pypi.tuna.tsinghua.edu.cn/simple说明: 不同版本的精度有差异,新版本精度不一定更高旧版本安装:+ pip install tr==2.8.1Windows 64位系统安装:pip install tr==2.8.6 -i https://pypi.org/simple/
Example 代码示例:
import trcrnn = tr.CRNN() # 初始化文本行识别网络chars, scores = crnn.run("imgs/line.png") # 识别文本行print("".join(chars)) # 打印结果
GUI 截图识别
# 需要安装PyQt5,PIL依赖python -m tr.gui
- c++接口支持
- 添加python2支持
- 去除opencv-python、Pillow依赖,降低部署难度
- 支持多线程
- python2/python3,需要安装numpy
- 不支持Windows、CentOS 6、ARM
由于新型号的显卡需要更高版本的CUDA,GPU版本暂时只支持旧型号的显卡。
如果对速度有要求,推荐安装GPU版本
要使用GPU版本,复制tr_gpu文件夹里面的文件到tr文件夹
注意: 需要先安装CUDA 10.1以及cuDNN 7.6.5。
若不想安装CUDA/cuDNN,可以使用docker部署
docker pull mcr.microsoft.com/azureml/onnxruntime:v1.3.0-cuda10.1-cudnn7sudo nvidia-docker run -v /path/to/tr:/path/to/tr --rm -it mcr.microsoft.com/azureml/onnxruntime:v1.3.0-cuda10.1-cudnn7
- 安装方法一
git clone https://github.com/myhub/tr.gitcd ./trsudo python setup.py install
- 安装方法二
sudo pip install git+https://github.com/myhub/tr.git@master
python2 demo.py # python2兼容测试python3 test.py # 可视化测试python3 test-multi-thread.py # 多线程测试python3 test_crnn_pyqt5.py # 截图识别
- 若需要Web端调用,推荐参考TrWebOCR
import tr# detect text lines, return list of (cx, cy, width, height, angle)print(tr.detect("imgs/web.png", tr.FLAG_RECT))# detect text lines with angle, return list of (cx, cy, width, height, angle)print(tr.detect("imgs/id_card.jpeg", tr.FLAG_ROTATED_RECT))# recognize text line, return (text, confidence)print(tr.recognize("imgs/line.png"))# detect and recognize text lines with angle, return list of ((cx, cy, width, height, angle), text, confidence)print(tr.run("imgs/id_card.jpeg"))
tr_init(0, 0, "crnn.bin", NULL);#define MAX_WIDTH512int unicode[MAX_WIDTH];float prob[MAX_WIDTH]; auto ws = tr_recognize(0, (void *)"line.png", 0, 0, 0, unicode, prob, MAX_WIDTH);tr_release(0);
About
Free Offline OCR 离线的中文文本检测+识别SDK
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.