【问题标题】:Google cloud vision face detection API with local files带有本地文件的谷歌云视觉人脸检测 API
【发布时间】:2018-07-14 10:08:23
【问题描述】:

我正在将我的相机与 Google Cloud Vision API 集成,以便计算房间内的总人数。但 API 只返回 10 个响应。

为了获得更多回复,我在features 中添加了max_results 字段。添加 max_results 字段后,它返回了 10 多个响应,但后来我得到的问题是它只接受带有“URI”的图像,我无法给它提供我系统上存在的图像。它只接受互联网上存在的图像,其图像地址如下面的代码所示。现在如何指定系统上存在的图像而不是提供 URI?

我用于获取图像和特征的 python 代码:

response = client.annotate_image({'image': {'source': {'image_uri':'http://im.rediff.com/news/2016/jan/26republic-day1.jpg'}}, 'features': [{'type': vision.enums.Feature.Type. FACE_DETECTION,'max_results':40}],})

【问题讨论】:

  • 目前尚不清楚这是两个独立的问题,其中一个您已经修复,或者它们是否只是一个组合问题。忽略 max_results,您可以使用本地文件吗?如果是这样,当您将 max_results 添加到请求时会发生什么?
  • 只有一个问题,我无法使用我的本地文件,因为它只获取图像的 URI,而本地文件没有任何 URI。
  • 在这种情况下,您应该将问题更改为提及该部分,因为它与 max_results 完全无关。
  • 接下来阅读这里的文档:cloud.google.com/vision/docs/reference/… 这向您展示了如何上传本地文件。
  • 我知道如何上传本地文件,但在上面的代码中,我想保留我的本地文件而不是 'image_uri',当我尝试这样做时,它没有检测到任何面孔。跨度>

标签: python google-cloud-vision


【解决方案1】:

工作sn-p:

import io
import os


# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types

# Instantiates a client
client = vision.ImageAnnotatorClient()

# The name of the image file to annotate
file_name = os.path.join(
    os.path.dirname(__file__),
    'face.jpeg')

# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
    content = image_file.read()

image = types.Image(content=content)

response = client.annotate_image({'image': image, 'features': [{'type': vision.enums.Feature.Type.FACE_DETECTION,'max_results':40}],})

print response

# Print joy likelihood
for face in response.face_annotations:
        print(face.joy_likelihood)

基本上,传递图像而不仅仅是文件名

【讨论】:

    猜你喜欢
    • 2016-07-03
    • 2017-02-04
    • 2019-03-22
    • 1970-01-01
    • 2016-03-10
    • 2019-10-07
    • 2018-04-07
    • 1970-01-01
    • 2016-06-02
    相关资源
    最近更新 更多