【发布时间】:2018-07-15 08:54:04
【问题描述】:
任务:
- 将 Google Vision API 响应转换为 JSON
问题:
- API 调用的返回值不是 JSON 格式
Python 函数
def detect_logos(path):
"""Detects logos in the file."""
client = vision.ImageAnnotatorClient()
# [START migration_logo_detection]
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = types.Image(content=content)
response = client.logo_detection(image=image)
logos = response.logo_annotations
print('Logos:')
print(logos)
print(type(logos))
Google 在线 JSON
"logoAnnotations": [
{
"mid": "/m/02wwnh",
"description": "Maxwell House",
"score": 0.41142157,
"boundingPoly": {
"vertices": [
{
"x": 74,
"y": 129
},
{
"x": 161,
"y": 129
},
{
"x": 161,
"y": 180
},
{
"x": 74,
"y": 180
}
]
}
}
Google 回复(列表)
[mid: "/m/02wwnh"
description: "Maxwell House"
score: 0.4114215672016144
bounding_poly {
vertices {
x: 74
y: 129
}
vertices {
x: 161
y: 129
}
vertices {
x: 161
y: 180
}
vertices {
x: 74
y: 180
}
}
]
类型:
google.protobuf.internal.containers.RepeatedCompositeFieldContainer
尝试过:
【问题讨论】:
-
您编写的 python 脚本是否只返回 Google 响应(列表),它是不带逗号返回的,还是只是您在这里的方式?
-
是的,它没有逗号,正是我粘贴的内容
-
你能在一个小的python脚本中提供一个简化版本的调用吗...我会运行它并找出问题的根源
-
当然,请检查。该函数调用视觉 API,我得到了我提到的响应。
标签: python json google-api