简体   繁体   English

Google Vision API错误代码

[英]Google Vision API Error Code

I am trying the example code in https://googlecloudplatform.github.io/google-cloud-python/stable/vision-usage.html 我正在尝试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. image.detect_safe_search对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 从Google api返回的响应是

{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. 我在api文档中找不到错误代码的任何引用。 What am I missing? 我想念什么?

Here's an issue which also mentions the error. 这是一个也提到该错误的问题 That issue has been forwarded to the Google engineering team. 该问题已转发给Google工程团队。

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? 将其另存为png或重新保存为jpg,以查看其是否已损坏或有其他问题?

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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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