问题
I want to read an image from Azure blob storage by using opencv 3 in Python 2.7. How to do this without downloading the blob to a local file?
回答1:
Per my experience, you can try to use get_blob_to_bytes
method to download the blob as a byte array and covert it to a opencv image, as my sample code below.
from azure.storage.blob import BlockBlobService
account_name = '<your-storage-account>'
account_key = '<your accout key>'
block_blob_service = BlockBlobService(account_name, account_key)
container_name = 'mycontainer'
blob_name = 'test.jpg'
blob = block_blob_service.get_blob_to_bytes(container_name, blob_name)
import numpy as np
import cv2
# use numpy to construct an array from the bytes
x = np.fromstring(blob.content, dtype='uint8')
# decode the array into an image
img = cv2.imdecode(x, cv2.IMREAD_UNCHANGED)
print img.shape
# show it
cv2.imshow("Image Window", img)
cv2.waitKey(0)
Hope it helps.
来源:https://stackoverflow.com/questions/44588402/how-can-i-read-an-image-from-azure-blob-storage-directly-using-opencv-without-do