如何让Vision API在图像上应用多个功能

时间:2016-02-05 17:42:34

标签: google-cloud-vision

如何调用Vision API并在图像上应用多个功能。 我想在图像上应用标签检测和地标检测

2 个答案:

答案 0 :(得分:1)

您可以按照以下方式定义请求,以便为每个图片合并多个功能请求

    "requests":[
    {
      "image":{
        "content":"/9j/7QBEUGhvdG9zaG9...image contents...fXNWzvDEeYxxxzj/Coa6Bax//Z"
      },
      "features":[
        {
          "type":"FACE_DETECTION",
          "maxResults":10
        },
        {
          "type":"LABEL_DETECTION",
          "maxResults":10
        }
      ]
    }
  ]
}  

答案 1 :(得分:0)

from google.cloud import vision
import os 

os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/path/client.json"

client = vision.ImageAnnotatorClient()
response = client.annotate_image({
      'image': {'source': {'image_uri': 'gs://yourbuket/1.jpg'}},
      'features': [{'type': vision.enums.Feature.Type.LABEL_DETECTION},
      {'type': vision.enums.Feature.Type.FACE_DETECTION}],
    })