1 服务端代码
from flask import request, Flask
import base64
import cv2
import numpy as np
app = Flask(__name__)
@app.route("/", methods=['POST','GET'])
def get_frame():
#解析图片数据
img = base64.b64decode(str(request.form['image']))
image_data = np.fromstring(img, np.uint8)
image_data = cv2.imdecode(image_data, cv2.IMREAD_COLOR)
cv2.imwrite('/root/01.png', image_data)
print(image_data)
return 'koukou'
if __name__ == "__main__":
app.run("10.0.0.160", port=5005)
2 客户端代码
import requests
import base64
#将图片数据转成base64格式
with open('/root', 'rb') as f:
img = base64.b64encode(f.read()).decode()
image = []
image.append(img)
res = {"image":image}
#访问服务
_ = requests.post("http://10.0.0.160:5005",data=res)