How can I read an image from Azure blob storage directly using Opencv without downloading it to a local file?

北城以北 提交于 2020-03-22 11:06:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!