README.md 4.1 KB
Newer Older
L
lywen 已提交
1 2
## 本项目基于[yolo3](https://github.com/pjreddie/darknet.git) 与[crnn](https://github.com/meijieru/crnn.pytorch.git)  实现中文自然场景文字检测及识别

L
lywen 已提交
3
###  darknet 优化版本:https://github.com/chineseocr/darknet-ocr.git 
L
lywen 已提交
4
# 训练代码(master分支)    
L
lywen 已提交
5

L
lywen 已提交
6 7 8 9 10
# ocr训练数据集     
ocr ctc训练数据集(压缩包解码:chineseocr)         
百度网盘地址:链接: https://pan.baidu.com/s/1UcUKUUELLwdM29zfbztzdw 提取码: atwn       
gofile地址:http://gofile.me/4Nlqh/uT32hAjbx   密码 https://github.com/chineseocr/chineseocr   
  
11 12
# 实现功能
- [x]  文字方向检测 0、90、180、270度检测(支持dnn/tensorflow) 
13 14
- [x]  支持(darknet/opencv dnn /keras)文字检测,支持darknet/keras训练
- [x]  不定长OCR训练(英文、中英文) crnn\dense ocr 识别及训练 ,新增pytorch转keras模型代码(tools/pytorch_to_keras.py)
W
wenlihaoyu 已提交
15 16 17 18 19 20 21 22
- [x]  支持darknet 转keras, keras转darknet, pytorch 转keras模型
- [x]  身份证/火车票结构化数据识别 
- [x]  新增CNN+ctc模型,支持DNN模块调用OCR,单行图像平均时间为0.02秒以下     
- [ ]  CPU版本加速    
- [ ]  支持基于用户字典OCR识别    
- [ ]  新增语言模型修正OCR识别结果  
- [ ]  支持树莓派实时识别方案  
 
23

L
lywen 已提交
24
## 环境部署
25

26
GPU部署 参考:setup.md     
27
CPU部署 参考:setup-cpu.md   
L
lywen 已提交
28

29 30

### 下载编译darknet(如果直接运用opencv dnn或者keras yolo3 可忽略darknet的编译)  
L
lywen 已提交
31 32 33 34 35 36 37 38 39 40
```
git clone https://github.com/pjreddie/darknet.git 
mv darknet chineseocr/
##编译对GPU、cudnn的支持 修改 Makefile
#GPU=1
#CUDNN=1
#OPENCV=0
#OPENMP=0
make 
```
41

42 43 44
修改 darknet/python/darknet.py line 48    
root = '/root/'##chineseocr所在目录     
lib = CDLL(root+"chineseocr/darknet/libdarknet.so", RTLD_GLOBAL)    
L
lywen 已提交
45 46


L
lywen 已提交
47
## 下载模型文件   
L
Lu Cao 已提交
48
模型文件地址:
L
lywen 已提交
49
* 百度网盘:https://pan.baidu.com/s/1gTW9gwJR6hlwTuyB6nCkzQ     
L
lywen 已提交
50
other-links:http://demo.xliane.com:11000/static/models/chineseocr/models/      
L
lywen 已提交
51
复制文件夹中的所有文件到models目录
52
   
53 54 55 56 57 58 59 60 61 62 63 64 65
## 模型转换
pytorch ocr 转keras ocr     
``` Bash
python tools/pytorch_to_keras.py  -weights_path models/ocr-dense.pth -output_path models/ocr-dense-keras.h5
```
darknet 转keras     
``` Bash
python tools/darknet_to_keras.py -cfg_path models/text.cfg -weights_path models/text.weights -output_path models/text.h5
```
keras 转darknet      
``` Bash
python tools/keras_to_darknet.py -cfg_path models/text.cfg -weights_path models/text.h5 -output_path models/text.weights
```
L
lywen 已提交
66

W
wenlihaoyu 已提交
67
## 模型选择  
L
lywen 已提交
68
``` Bash
W
wenlihaoyu 已提交
69 70
参考config.py文件
```  
L
lywen 已提交
71

W
wenlihaoyu 已提交
72 73 74 75 76 77 78 79 80 81
## 构建docker镜像 
``` Bash
##下载Anaconda3 python 环境安装包(https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh) 放置在chineseocr目录下   
##建立镜像   
docker build -t chineseocr .   
##启动服务   
docker run -d -p 8080:8080 chineseocr /root/anaconda3/bin/python app.py

```

W
wenlihaoyu 已提交
82 83 84 85 86 87 88 89 90 91 92 93
## web服务启动
``` Bash
cd chineseocr## 进入chineseocr目录
python app.py 8080 ##8080端口号,可以设置任意端口
```

## 访问服务
http://127.0.0.1:8080/ocr

<img width="500" height="300" src="https://github.com/chineseocr/chineseocr/blob/master/test/demo.png"/>


W
wenlihaoyu 已提交
94

L
lywen 已提交
95
## 识别结果展示
L
lywen 已提交
96

97 98 99 100
<img width="500" height="300" src="https://github.com/chineseocr/chineseocr/blob/master/test/train-demo.png"/>
<img width="500" height="300" src="https://github.com/chineseocr/chineseocr/blob/master/test/idcard-demo.png"/>
<img width="500" height="300" src="https://github.com/chineseocr/chineseocr/blob/master/test/img-demo.png"/>
<img width="500" height="300" src="https://github.com/chineseocr/chineseocr/blob/master/test/line-demo.png"/>
L
lywen 已提交
101

L
Lu Cao 已提交
102

L
lywen 已提交
103 104 105 106 107

## 参考
1. yolo3 https://github.com/pjreddie/darknet.git   
2. crnn  https://github.com/meijieru/crnn.pytorch.git              
3. ctpn  https://github.com/eragonruan/text-detection-ctpn    
108
4. CTPN  https://github.com/tianzhi0549/CTPN       
109 110
5. keras yolo3 https://github.com/qqwweee/keras-yolo3.git    
6. darknet keras 模型转换参考 参考:https://www.cnblogs.com/shouhuxianjian/p/10567201.html  
111
7. 语言模型实现 https://github.com/lukhy/masr
L
lywen 已提交
112 113 114 115 116


## 技术支持   
mail:chineseocr@hotmail.com  
wechat:lywen52