我在GCS上有一堆图片,想知道它们是什么?
答案 0 :(得分:5)
对于GCS集成 - 我只需通过用gcs_image_uri替换内容属性来修改上面的主体以指向GCS位置
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()
答案 1 :(得分:2)
可以通过REST API调用访问Vision 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