googlecloudvisionapi客户端库
visionar的Python项目详细描述
用于google cloud vision api的python客户端库
https://cloud.google.com/vision
安装
库可以与pip一起安装:pip install visionary
用法
用法示例:
fromvisionaryimportGoogleCloudVision,LabelDetection,LogoDetectionAPI_KEY="dummy_api_key"client=GoogleCloudVision(API_KEY)# Ask for logo detection, 10 results maxresponse=client.annotate("dummy.jpg",LogoDetection())# Ask for label detection, 3 results maxresponse=client.annotate("dummy.jpg",LabelDetection(3))
检测参数可以显式设置:
# 5 results max for logo detection and only one result for label detectionresponse=client.annotate("dummy.jpg",LogoDetection(5),LabelDetection(1))
第一个参数可以是文件对象:
uploaded_file=open("dummy.jpg")...# somewhere laterresponse=client.annotate(uploaded_file)
或网址:
response=client.annotate("http://google.com/dummy.jpg")
客户端支持单个注释中的多个图像调用
response=client.annotate(("dummy.jpg"),("http://google.com/dummy.jpg"),("dummy.jpg",LogoDetection(1)),)
处理响应:
ifresponse.ok:forrespinresponse.responses:foriinresp.logo_annotations:print(i.description)else:print(response.error['code'],response.error['message'],response.error['status'])