日日行,不怕千万里;常常做,不怕千万事|

__username

园龄:2年4个月粉丝:12关注:2

📂python
🔖Python
2023-08-24 18:54阅读: 31评论: 0推荐: 0

ocr 文字识别 服务

ocr 文字识别 服务

利用百度开源模型:地址:https://github.com/PaddlePaddle/PaddleHub/tree/develop/modules/image/text_recognition/chinese_ocr_db_crnn_mobile

一个开发web服务demo

from flask import Flask, render_template, request, jsonify
import requests, json
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
processed_data = None
if request.method == 'POST':
try:
json_data = request.get_json() # 获取POST请求中的JSON数据
if 'image_data' in json_data:
# 假设用户发送的JSON中有一个名为 "image_data" 的字段
image_data = json_data['image_data'] # 这是属于base64加密字段
# 在这里可以对图像数据进行处理
processed_data = process_image_data(image_data)
except Exception as e:
error_message = str(e)
return jsonify({"error": error_message})
if processed_data:
return jsonify({"result": processed_data})
else:
return jsonify({"message": "No data processed."})
def process_image_data(image_data):
# # 在这里进行图像数据处理的实际操作
# # 这个函数是一个示例,根据实际需求来实现图像数据的处理逻
data = {'images': [image_data]}
headers = {"Content-type": "application/json"}
url = "http://127.0.0.1:8866/predict/chinese_ocr_db_crnn_mobile"
r = requests.post(url=url, headers=headers, json=data)
# 打印预测结果
print(r.json()["results"])
r.close()
return r.json()["results"]
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5522, debug=True)
posted @   __username  阅读(31)  评论(0编辑  收藏  举报

本文作者:DIVMonster

本文链接:https://www.cnblogs.com/guangzan/p/12886111.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起