简体   繁体   中英

Google Vision API Error Code

I am trying the example code in https://googlecloudplatform.github.io/google-cloud-python/stable/vision-usage.html

from google.cloud import vision
   client = vision.Client()
   image = client.image('./image.jpg')
   safe_search = image.detect_safe_search()

image.detect_safe_search throws a key error for the result returned from api. On printing the result dict, I found the it didn't have the expected key because it gave error response. The response returned from google api is

{u'error': {u'message': u'image-annotator::error(12): Image processing error!', u'code': 13}}

I could not find any references for the error code in the documentation of api. What am I missing?

Here's an issue which also mentions the error. That issue has been forwarded to the Google engineering team.

Could you perhaps try re-encoding your image? Save it as a png or resave to jpg to see if maybe it's corrupted or anything?

It appears that the documentation is incorrect.

This example works.

from google.cloud import vision

client = vision.Client()

with open('yourimage.jpg', 'rb') as file_obj:
    my_image = client.image(content=file_obj.read())
results = my_image.detect_safe_search()

print(results[0].medical)
# 'VERY_UNLIKELY'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM