我的应用程序是在客户端打开摄像头,获取帧,在后端对其执行机器学习过程,然后将其返回给客户端。
这部分代码(以粗体显示)抛出错误 - PngImageFile' 对象没有属性 'shape'。
此代码行有问题 -frame = imutils.resize( pimg, width=700)
我猜有些处理的格式不正确。请指导
@socketio.on('image')
def image(data_image):
sbuf = io.StringIO()
sbuf.write(data_image)
# decode and convert into image
b = io.BytesIO(base64.b64decode(data_image))
pimg = Image.open(b)
# Process the image frame
frame = imutils.resize(**pimg,** width=700)
frame = cv2.flip(frame, 1)
imgencode = cv2.imencode('.jpg', frame)[1]
# base64 encode
stringData = base64.b64encode(imgencode).decode('utf-8')
b64_src = 'data:image/jpg;base64,'
stringData = b64_src + stringData
# emit the frame back
emit('response_back', stringData)
Run Code Online (Sandbox Code Playgroud)