2016-02-05 56 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

相關問題