python-3.x - 一次 API 调用中的 Google Cloud Vision API 多个图像注释

标签 python-3.x google-cloud-platform google-cloud-vision

我正在尝试使用 Cloud Vision API客户端检测图像中的“标签”和人脸。

我可以检测像 this 这样的标签关键的代码行是:

response = client.label_detection(image=image)
labels = response.label_annotations

并用于检测 faces :
response = client.face_detection(image=image)
faces = response.face_annotations

所以,目前我可以进行两次 API 调用来获取我需要的信息,但如果可能的话,我想将它们合并为一个 API 调用。

更新:

我找到了 annotate_image()可以接受此功能列表的方法 page :
response = client.annotate_image({
    'image': {'source': {'image_uri': 'gs://my-test-bucket/image.jpg'}},
    'features': [{'type': vision.enums.Feature.Type.FACE_DETECTION}],
})

但是图像源只接受图像的 URL 或其在 GCP 上的路径。我想对本地存储的图像进行分析,这可能吗?

最佳答案

您要找的是Batching Request ,它允许您在一个 API 请求中发送多个文件或多个功能。看看Batching Requests文档。

要在一个 API 请求中使用多个功能,请查看此 Cloud Vision API Feature文档。您会找到您可以请求的所有类型的不同功能。

我自己做了一些编码,它对我有用。它从本地存储读取图像,并在一个 API 请求中打印 LABEL 和 FACE 检测结果。你可以找到我的 GitHub code here .

关于python-3.x - 一次 API 调用中的 Google Cloud Vision API 多个图像注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54274309/

相关文章:

java - Google Vision Java 客户端批量请求响应识别

python 3 根据条件获取列名

Python-将特定文件从列表复制到新文件夹中

google-cloud-platform - Terraform:将文件复制到 GCP 计算实例

android - Google Cloud Vision - 无法在包含 2 列文本的图像上提供良好的 OCR

python - 使用 GCP 的 Cloud Vision 进行车牌识别

python - 为什么我在 PyGame 中得到空白的灰色背景而不是动画?

javascript - 将谷歌日历 API 集成到 React hooks

mysql - AppEngine 和 Cloud SQL 连接错误

firebase - Firebase Cloud Functions 中的返回值重要吗