2016-02-05 32 views

回答

5

对于GCS集成 - 我只想修改上面的身体指向GCS位置用gcs_image_uri替换内容属性

​​
2

Vision API可以通过REST API调用访问。您传入JSON请求,其中嵌入了图像或链接到GCS中的图像。然后,您可以传入要在图像上运行的功能。这是作为JSON请求传入的,响应对象包含注释。以下是调用Vision API的Python代码片段。

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'] 

有关其他信息,您不妨看看Label Detection Tutorial

相关问题