ocr 文字识别 服务
ocr 文字识别 服务
一个开发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)
本文来自博客园,作者:__username,转载请注明原文链接:https://www.cnblogs.com/code3/p/17654949.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步