0

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?

  • I had the same issue with domain.com/xzy.jpg, it was because there was an .htaccess rule that was forwarding domain.com/xzy.jpg to www.domain.com/xyz.jpg. Sending the image url with www. solved the issue. – Sherif Buzz Apr 23 '17 at 20:32

2 Answers2

0

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?

Serge Hendrickx
  • 1,416
  • 9
  • 15
0

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'
Thomas Schultz
  • 2,446
  • 3
  • 25
  • 36