我有一个azure blob存储帐户和一些图像。我想将它们读取为用于图像处理的字节,这样我就可以将它们与Microsoft的Face API一起使用。我收到一条错误消息,告诉我需要一个“Bytes”对象,但我想我已经在将图像从blob转换为byte格式了。我已经提供了我使用的全部代码,但问题来自最后一段代码
%matplotlib inline
import matplotlib.pyplot as plt
import io
from io import StringIO
import numpy as np
import cv2
from PIL import Image
from PIL import Image
import os
from array import array
我的凭据:
azure_storage_account_name = 'musicsurveyphotostorage'
azure_storage_account_key = None
blob...
if azure_storage_account_name is None:
raise Exception("You must provide a name for an Azure Storage account")
from azure.storage.blob import BlockBlobService
blob_service = BlockBlobService(azure_storage_account_name,
azure_storage_account_key)
选择blob存储容器
container_name = 'musicsurveyphotostorage'
generator = blob_service.list_blobs(container_name)
blob_prefix = 'https://{0}.blob.core.windows.net/{1}/{2}'
正在加载图像。。错误来自以下代码块:
blob_name = 'shiba.jpg' #name of image I have stored
blob = blob_service.get_blob_to_bytes(container_name, blob_name)
image_file_in_mem = io.BytesIO(blob)
img_bytes = Image.open(image_file_in_mem)
我收到的错误消息如下:
TypeError Traceback (most recent call last)
<ipython-input-13-6738e5733c01> in <module>()
36 blob_name = 'shiba.jpg' #name of image I have stored
37 blob = blob_service.get_blob_to_bytes(container_name, blob_name)
**
39 img_bytes = Image.open(image_file_in_mem)
TypeError: a bytes-like object is required, not 'Blob'