百度将待检查图片保存为base64的形式进行图片传输,客户端的代码:
服务器端的代码:
# coding:utf-8 from flask import Flask, request import numpy as np import base64 import cv2 from datetime import datetime import random app = Flask(__name__) @app.route('/', methods=['POST', 'GET']) ##defined the name of image class Rename_str: def create_uuid(self): nowTime = datetime.now().strftime("%Y%m%d%H%M%S") randomNum = random.randint(0, 100) if randomNum < 10: randomNum = str(0)+str(randomNum) uniqueNum = str(nowTime)+str(randomNum) return uniqueNum def vot_invoice(): img = base64.b64decode(str(request.form['image'])) image_data = np.fromstring(img, np.uint8) rename = Rename_str().create_uuid() img_np = cv2.imdecode(image_data, cv2.IMREAD_COLOR) cv2.imwrite('C:/Users/ASIA/Downloads/LabelWeb-master/templates/images/{}.jpg'.format(rename), img_np) return 'ok' if __name__ == "__main__": app.run(host='127.0.0.1', port=8987)