Search code examples
pythongoogle-cloud-vision

How do I call the Google Vision API with an image stored in Google Cloud Storage?


I have a bunch of pictures on GCS and would like to figure out what they are?


Solution

  • For GCS Integration - I would just modify the above body to point to the GCS location by replacing content attribute with gcs_image_uri

        batch_request = [{
        'image': {
            'source': {
                'gcs_image_uri': "gs://bucket_name/object_path"
            }
        },
        'features': [{
            'type': 'LANDMARK_DETECTION',
            'maxResults': max_results,
            }]
        }]
    service = get_vision_service()
    request = service.images().annotate(body={
        'requests': batch_request,
        })
    response = request.execute()