Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I ask the Vision API to apply multiple features on an image

How do I call the Vision API and apply more than one feature on an image. I want to apply both Label Detection and the landmark detection on an image

like image 299
Ram Ramanathan Avatar asked Oct 18 '22 16:10

Ram Ramanathan


2 Answers

You can define your request as below to incorporate multiple feature requests per image

    "requests":[
    {
      "image":{
        "content":"/9j/7QBEUGhvdG9zaG9...image contents...fXNWzvDEeYxxxzj/Coa6Bax//Z"
      },
      "features":[
        {
          "type":"FACE_DETECTION",
          "maxResults":10
        },
        {
          "type":"LABEL_DETECTION",
          "maxResults":10
        }
      ]
    }
  ]
}  
like image 53
Ram Ramanathan Avatar answered Dec 20 '22 17:12

Ram Ramanathan


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}],
    })
like image 26
ryan Li Avatar answered Dec 20 '22 17:12

ryan Li