背景
PaddleOCR简介
PaddleOCR旨在打造一套丰富、领先、且实用的OCR工具库,助力使用者训练出更好的模型,并应用落地。
目的
通过这篇文章,我们可以搭建一个图像识别文字的服务器,需要注意的是,本文采取的是傻瓜式
的搭建,如果需要细致了解,请看PaddleOCR文档
搭建
前提
Linux
(本文所采用的系统为centos7) 需安装Python3
步骤
克隆代码
1
|
git clone https://gitee.com/sheaxiang/paddleocr.git
|
这是我根据PaddleOCR文章安装配置,集成了相关检测识别模型,只需要克隆
此代码,就可以了
基础安装
安装PaddlePaddle 2.0
1
|
python3 -m pip install paddlepaddle==2.0.0 -i https://mirror.baidu.com/pypi/simple
|
安装项目依赖
1
2
|
# 这里的pip3.6 可以根据自己系统情况更改
pip3.6 install -r requirements.txt
|
服务端安装
安装paddlehub
1
|
pip3 install paddlehub --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple
|
安装服务模块
1
2
3
4
5
6
7
8
|
# 安装检测服务模块:
hub install deploy/hubserving/ocr_det/
# 或,安装分类服务模块:
hub install deploy/hubserving/ocr_cls/
# 或,安装识别服务模块:
hub install deploy/hubserving/ocr_rec/
# 或,安装检测+识别串联服务模块:只安装了这个
hub install deploy/hubserving/ocr_system/
|
启动(配置文件方式)
在项目根目录,会监听端口8868,自定义可配置config.json
1
|
hub serving start -c config.json
|
使用
接口
请求接口url: http://127.0.0.1:8868/predict/ocr_system,POST
方式, 需设置header: {'content-type': 'application/json'}
,参数为 images[]
, 值类型为图片的base64
, 下面给个小程序
的请求示例
1
2
3
4
5
6
7
8
9
10
11
12
13
|
wx.request({
url: 'http://127.0.0.1:8868/predict/ocr_system',
method: 'POST',
data: {
images: [wx.getFileSystemManager().readFileSync(res.tempFilePaths[0],'base64')]
},
header: {
'content-type': 'application/json'
},
success (res) {
console.log(res);
}
})
|
体验
使用微信
扫一扫
