本文介绍了如何直接使用Opencv从Azure Blob存储读取图像,而不将其下载到本地文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过在Python 2.7中使用opencv 3从Azure blob存储中读取图像.如何在不将Blob下载到本地文件的情况下执行此操作?
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?
推荐答案
根据我的经验,您可以尝试使用get_blob_to_bytes
方法将blob下载为字节数组并将其秘密转换为opencv图像,作为我的示例代码在下面.
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)
希望有帮助.
这篇关于如何直接使用Opencv从Azure Blob存储读取图像,而不将其下载到本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!