本文介绍了导入图像Azure Machine Learning Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从Python脚本模块中的Azure存储帐户中导入图像,而不是使用Azure ML Studio提供的导入图像"模块.理想情况下,我想使用cv2.imread().我只想读取灰度数据,但是导入图像"模块以RGB读取.我可以像使用外部Python脚本一样使用BlockBlobService库吗?

Is it possible to import images from your Azure storage account from within a Python script module as opposed to using the Import Images module that Azure ML Studio provides. Ideally I would like to use cv2.imread(). I only want to read in grayscale data but the Import Images module reads in RGB.Can I use the BlockBlobService library as if I were calling it from an external Python script?

推荐答案

基于我的理解,我认为您想通过python-opencv2的方法cv2.imread从Azure Blob存储获取图像的灰度数据.

Based on my understanding, I think you want to get the grayscale data of a image which comes from Azure Blob Storage via the method cv2.imread of python-opencv2.

我试图用azure-storage==0.20.3包编写一个python脚本来做到这一点.这是我的示例代码,如下所示.

I tried to write a python script using azure-storage==0.20.3 package to do it. Here is my sample code as below.

from azure.storage.blob import BlobService
import numpy
import cv2

service = BlobService(account_name='<your storage account name>', account_key='<your storage account key>')
blob = service.get_blob_to_bytes('mycontainer', 'test.jpg')
print type(blob)
np_array = numpy.fromstring(blob, numpy.uint8)
print np_array
img = cv2.imdecode(np_array, cv2.CV_LOAD_IMAGE_COLOR)

如果使用最新的azure-storage软件包,请确保使用以下代码.

If using the latest azure-storage package, make sure that using the code as below.

from azure.storage.blob import BlockBlobService

service = BlockBlobService(account_name='<your storage account name>', account_key='<your storage account key>')

上面的代码在本地环境下可以正常工作,但是由于缺少必需的Python包azure-storage& ;;而不能在Azure ML Studio的Experiments上用作Execute Python Script模块. cv2.然后,我尝试遵循文档 Adding Python Script as a Custom Resource 添加这些软件包,但是未能意识到python-opencv2软件包依赖于C本机库opencv2.

The code above works fine on local environment, but it doesn't work as a Execute Python Script module on the Experiments of Azure ML Studio, because of missing the required Python packages azure-storage & cv2. Then I tried to follow the document Adding Python Script as a Custom Resource to add these packages, but failed that I realized the python-opencv2 package is depended on the C native library opencv2.

因此,根据我的经验,我认为简单的&解决方法是使用OpenCV Library ModulesImport Images模块的dataframe中的RGB数据计算灰度数据.

So per my experience, I think the simple & workaround way is that computing the grayscale data with the RGB data in dataframe from Import Images module of OpenCV Library Modules.

希望有帮助.

这篇关于导入图像Azure Machine Learning Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 18:59