我想在我的 Flask API 中以字节为单位发送和接收图像。我还想在图像旁边发送一些 json。我怎样才能实现这个目标?
以下是我当前的解决方案,不起作用
烧瓶:
@app.route('/add_face', methods=['GET', 'POST'])
def add_face():
if request.method == 'POST':
# print(request.json)
nparr = np.fromstring(request.form['img'], np.uint8)
print(request.form['img'])
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
cv2.imshow("frame", img)
cv2.waitKey(1)
return "list of names & faces"
Run Code Online (Sandbox Code Playgroud)
客户:
def save_encoding(img_file):
URL = "http://localhost:5000/add_face"
img = open(img_file, 'rb').read()
response = requests.post(URL, data={"name":"obama", "img":str(img)})
print(response.content)
Run Code Online (Sandbox Code Playgroud)
产生错误:
cv2.imshow("frame", img)
cv2.error: OpenCV(3.4.3) /io/opencv/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
Run Code Online (Sandbox Code Playgroud)