Skip to content

Commit

Permalink
更新readme,增加restful服务说明
Browse files Browse the repository at this point in the history
  • Loading branch information
yizt committed Apr 10, 2020
1 parent 0abbfe0 commit 82d08c6
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# crnn.pytorch

[TOC]

​ 本工程使用随机生成的水平和垂直图像训练crnn模型做文字识别;一共使用10多种不同字体;共包括数字、字符、简体和繁体中文字30656个,详见[all_words.txt](data/all_words.txt)


## 预测
### 直接预测

预训练模型下载地址:水平模型 [crnn.horizontal.060.pth](https://pan.baidu.com/s/1NxR6XwJgPx9kslbFMO0X0A) 提取码: k92d; 垂直模型 [crnn.vertical.090.pth](https://pan.baidu.com/s/1VsW2K4G0g0QX5W3Lb3SoAw) 提取码: ygx7。

a) 执行如下命令预测单个图像
Expand All @@ -18,7 +22,35 @@ b) 执行如下命令预测图像目录
python demo.py --weight-path /path/to/chk.pth --image-dir /path/to/image/dir
```

### 使用restful服务预测

a) 启动restful服务

```shell
python rest.py -l /path/to/crnn.horizontal.060.pth -v /path/to/crnn.vertical.090.pth
```

b) 使用如下代码预测,参考`rest_test.py`

```python
import codecs
import cv2
import requests

img = cv2.imread('./images/horizontal-002.jpg', 0)
h, w = img.shape
data = {'img': codecs.encode(img.tostring(), 'base64'), # 转为字节,并编码
'shape': [h, w]}
r = requests.post("http://localhost:5000/crnn", data=data)

print(r.json()['text'])
```

结果如下:

```shell
厘鳃 銎 萛闿 檭車 垰銰 陀 婬2 蠶
```



Expand Down

0 comments on commit 82d08c6

Please sign in to comment.