我正在尝试将数据发送到Algorithmia服务器,但是将图像发送到服务器却使我发疯。首先,我尝试使用base64,但它会产生许多错误。现在,我试图将其转换为bytesarray。但是一旦转换为字节数组,便无法转换回图像。我已阅读的所有解决方案都是读取字节数组文件,然后转换为图像,但是我无法保存图像,然后再次读取它。
我尝试使用将字节数组转换为图像。
img = Image.open(io.BytesIO(input))
但是当我运行它时,会弹出以下错误消息
OSError: cannot identify image file <_io.BytesIO object at 0x7fde73f4edb0>
这是代码,我正在使用:
img = cv2.imread("/home/abdullah/Desktop/Profile.png")
img = cv2.resize(img, (512, 512))
input = bytearray(img)
img = Image.open(io.BytesIO(input))
请告诉我一个解决方案,该解决方案将为我提供图像的2 numpy数组而不是平面数组,因此我可以使用它将其输入到模型中。