如何使用 Opencv 直接从 Azure blob 存储中读取图像而不将其下载到本地文件?
How can I read an image from Azure blob storage directly using Opencv without downloading it to a local file?
我想在 Python 2.7 中使用 opencv 3 从 Azure blob 存储中读取图像。
如何在不将 blob 下载到本地文件的情况下执行此操作?
根据我的经验,您可以尝试使用 get_blob_to_bytes
方法将 blob 下载为字节数组并将其转换为 opencv 图像,如下面的示例代码。
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)
希望对您有所帮助。
我想在 Python 2.7 中使用 opencv 3 从 Azure blob 存储中读取图像。 如何在不将 blob 下载到本地文件的情况下执行此操作?
根据我的经验,您可以尝试使用 get_blob_to_bytes
方法将 blob 下载为字节数组并将其转换为 opencv 图像,如下面的示例代码。
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)
希望对您有所帮助。