What can 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 find out what they are?

+5
source share
2 answers

For GCS integration - I would just modify the above body to indicate the location of GCS, replacing the 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() 
+5
source

Access to the Vision API can be obtained through a call to the REST API. You submit a JSON request with an embedded image or image link in GCS. Then you can pass the functions you want to run on the image. This is passed as a JSON request, and the response object contains annotations. Here is a snippet of Python code calling the Vision API.

 DISCOVERY_URL='https://{api}.googleapis.com/$discovery/rest?version={apiVersion}' credentials = GoogleCredentials.get_application_default() service = discovery.build('vision', 'v1', credentials=credentials, discoveryServiceUrl=DISCOVERY_URL) with open(photo_file, 'rb') as image: image_content = base64.b64encode(image.read()) service_request = service.images().annotate( body={ 'requests': [{ 'image': { 'content': image_content }, 'features': [{ 'type': 'LABEL_DETECTION', # Feature to detect 'maxResults': 1, }] }] }) response = service_request.execute() label = response['responses'][0]['labelAnnotations'][0]['description'] 

For more information, you can see the Label Detection Tutorial.

+2
source

Source: https://habr.com/ru/post/1242335/


All Articles