4 Star 17 Fork 10

ouyanghuiyu/chineseocr_lite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
flask_app.py 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
Pad0y 提交于 2020-07-24 11:18 . update
import os
from flask import Flask
from flask_restful import Api, Resource, reqparse
from config import version
from utils import app_url
from apphelper.image import base64_to_PIL
import numpy as np
from model import text_predict
app = Flask(__name__)
api = Api(app)
class ImageIdentify(Resource):
# http://ip:port/api/v1/ocr
def post(self, **kwargs):
parser = reqparse.RequestParser()
parser.add_argument('ImgString', type=str,
required=True, location='form')
args = parser.parse_args()
rst = None
imgString = args['ImgString'].encode().split(b';base64,')[-1]
try:
b64_image = base64_to_PIL(imgString)
if b64_image is not None:
b64_image = np.array(b64_image)
result = text_predict(b64_image)
text = ' '.join([i['text'] for i in result])
rst = {
'code': "success",
'text': text
}
except ValueError:
rst = {
"code": "FAILURE",
"errMsg": "ocr访问出错",
"id": "1501"
}
return rst
api.add_resource(ImageIdentify, app_url(version, '/ocr'))
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=False)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ouyanghuiyu/chineseocr_lite.git
git@gitee.com:ouyanghuiyu/chineseocr_lite.git
ouyanghuiyu
chineseocr_lite
chineseocr_lite
master

搜索帮助