2025-11-14 09:53:34 +08:00
new
2024-04-29 10:09:31 +08:00
new
2024-04-29 10:09:31 +08:00
new
2024-05-17 15:46:04 +08:00
new
2023-06-13 13:00:04 +08:00
new
2023-06-13 13:00:04 +08:00
new
2023-06-13 13:00:04 +08:00
new
2024-05-24 17:01:50 +08:00
new
2023-08-30 13:25:32 +08:00
new
2023-12-21 17:17:28 +08:00
new
2023-06-13 13:00:04 +08:00
new
2024-03-27 15:04:36 +08:00
new
2023-06-13 13:00:04 +08:00
new
2023-08-30 15:37:01 +08:00
new
2023-06-13 13:00:04 +08:00
2025-11-14 09:53:34 +08:00
new
2023-07-05 14:20:11 +08:00
new
2023-07-05 14:20:11 +08:00
new
2023-06-13 13:00:04 +08:00
new
2023-06-13 13:00:04 +08:00

tr - Text Recognition

一款针对扫描文档的离线文本识别SDK核心代码全部采用C++开发并提供Python接口

编译环境: Ubuntu 16.04

为什么开发tr

我刚开发tr时网上只有chineseocrtesseract等少数开源OCR。tr发布后又诞生了几款优秀的开源OCR。tr也基本上完成了自己的使命会转为一个研究型项目追求技术的先进性而不是实用性。

暂停维护说明

在研究OCR的过程中我发现了更有趣的Transformer技术这是一种有希望单个算法解决绝大部分深度学习任务包括OCR的技术。未来的算法工程师可能不再需要学习各种各样的算法只需要学习一款算法即可。后续我们将暂停维护本项目重点研究Transformer技术

更新说明

  • c++接口支持
  • 添加python2支持
  • 去除opencv-python、Pillow依赖降低部署难度
  • 支持多线程

Requirements

  • python2/python3需要安装numpy
  • 不支持Windows、CentOS 6、ARM

GPU版本安装说明

由于新型号的显卡需要更高版本的CUDAGPU版本暂时只支持旧型号的显卡。
如果对速度有要求推荐安装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-cudnn7
sudo nvidia-docker run -v /path/to/tr:/path/to/tr --rm -it mcr.microsoft.com/azureml/onnxruntime:v1.3.0-cuda10.1-cudnn7

Install

  • 安装方法一
git clone https://github.com/myhub/tr.git
cd ./tr
sudo python setup.py install
  • 安装方法二
sudo pip install git+https://github.com/myhub/tr.git@master

Test

python2 demo.py               # python2兼容测试
python3 test.py               # 可视化测试
python3 test-multi-thread.py  # 多线程测试
python3 test_crnn_pyqt5.py    # 截图识别

关联项目

  • 若需要Web端调用推荐参考TrWebOCR

Python Example

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"))

C++ Example

tr_init(0, 0, "crnn.bin", NULL);

#define MAX_WIDTH		512
int 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);

效果展示


Description
Free Offline OCR 离线的中文文本检测+识别SDK
Readme Apache-2.0 530 MiB
Languages
Python 100%