如何在 Google Cloud Vision API 上一次呼叫 "Label Detection" 和 "Safe Search Detection"

How to call for "Label Detection" and "Safe Search Detection" at a time on Google Cloud Vision API

我想请教您以下关于Vision的事情API。

下图表示我可以拿"Free with Label Detection, or .50",如果我会用"Label Detection"。 但是,我没有在关于 "Label Detection" 和 "Safe Search Detection" 的教程中找到如何同时使用它们。

  1. 我可以在 Python 中同时使用这两项服务吗?
  2. 如果是这样,我该如何打电话给他们?

如果你告诉我,我将不胜感激。

如果你想同时发送两种类型,你可以使用annotate_image()方法;通过这种方式,您可以指定需要包含在同一个请求中的所有 features。基于此,我建议您查看此文档(Doc1, Doc2) to get detailed information about this property usage, as well as this tutorial,其中包含一个 curl 命令示例,其中显示了在同一调用中发送多个功能所需的过程,您可以将其用作替代解决方法。

import io
import os

from google.cloud import vision

client = vision.ImageAnnotatorClient()

response = client.annotate_image({
  'image': {'source': {'image_uri': '<IMAGE_URI>'}},
  'features': [{'type': vision.enums.Feature.Type.SAFE_SEARCH_DETECTION},
               {'type': vision.enums.Feature.Type.LABEL_DETECTION}]
})

print(response)

此外,我认为此定价信息是指如果您将 安全搜索检测 功能与 标签检测[=23] 一起使用,则可以免费使用它=];但是,标签检测 请求将按照 Prices 文档中显示的相应费用计费。