【问题标题】:Passing PIL cropped image as stream in Azure Computer Vision在 Azure 计算机视觉中将 PIL 裁剪图像作为流传递
【发布时间】:2021-09-27 21:46:41
【问题描述】:

我需要将裁剪后的图像作为流或 url 传递给 Azure 中的计算机视觉客户端。我正在使用 PIL 根据一些边界框值裁剪图像。 img1 存储裁剪后的图像

img1 = img.crop((bbox[i][0], bbox[i][1], bbox[i][4], bbox[i][5]))
img1.show()
with open(img1.name, 'rb') as bg_image1:
     colour_analysis = computervision_client.analyze_image_in_stream(bg_image1, remote_image_features)

img1 = img.crop((bbox[i][0], bbox[i][1], bbox[i][4], bbox[i][5]))
img1.show()
open_image = open(img1.name, "rb")
colour_analysis = computervision_client.analyze_image_in_stream(open_image, remote_image_features)
          

当我运行上面的代码时,我得到了错误:raise AttributeError(name) AttributeError: name

以前,当我从文件上传图像时,我使用了这段代码,效果很好:

with open('filepath\filename.jpg', 'rb') as bg_image:
    colour_analysis = computervision_client.analyze_image_in_stream(bg_image, remote_image_features)

如何将裁剪后的图像传递给 Azure 客户端?

【问题讨论】:

  • 能否请您添加有关您添加的 remote_image_features 的更多详细信息。
  • 这是一个包含要分析的特征的简单列表,在我的例子中是背景颜色。

标签: python azure file file-upload python-imaging-library


【解决方案1】:

请按照以下 github 示例分析本地图像。请参阅 ComputerVisionClient 方法,例如 AnalyzeImageInStreamAsync。

https://github.com/Azure-Samples/cognitive-services-quickstart-code/blob/master/dotnet/ComputerVision/ImageAnalysisQuickstart.cs#L306

【讨论】:

    猜你喜欢
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 2019-12-20
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多