服务端
from flask import Flask,request,render_template
from flask import session,redirect,jsonify
import cv2
import numpy as np
import base64
import os
import fastdeploy as fd
import datetime,timeapp=Flask(__name__)from logging import config,getLogger
logger=getLogger('WebAPI')def get_image_data():"""将客户端传入的图片数据(base64字符串格式)转成numpy.ndarray格式"""params = request.jsonif not params["images"]: # 列表为空return "No image received, please check"img = params["images"]try:img = base64.b64decode(img)img = np.frombuffer(img, np.uint8)img = cv2.imdecode(img, cv2.IMREAD_COLOR)except Exception as e:print(e)return "Not valid image type!"return imgdef cv2_to_base64(image, img_type=".bmp"):"""将cv2 numpy ndarray格式的图片数据转成s