【发布时间】:2021-05-04 14:36:59
【问题描述】:
我使用以下代码,它看起来像 client.text_detection 必须接收图像。相反,我只想发送图像的 base64 编码文本字符串。最好的方法是什么?
def detect_text(path): """Detects text in the file.""" client = vision.ImageAnnotatorClient()
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)
response = client.text_detection(image=image)
texts = response.text_annotations
print('Texts:')
for text in texts:
print('\n"{}"'.format(text.description))
vertices = (['({},{})'.format(vertex.x, vertex.y)
for vertex in text.bounding_poly.vertices])
print('bounds: {}'.format(','.join(vertices)))
if response.error.message:
raise Exception(
'{}\nFor more info on error messages, check: '
'https://cloud.google.com/apis/design/errors'.format(
response.error.message))
【问题讨论】:
-
看起来您正在发送请求中的图像内容。你有错误吗?错误是什么?
-
根据您的代码,我假设您正在关注此tutorial。您不需要使用此 python 示例进行 base64 编码,它适用于您的图像路径。
-
如果您仍然想只发送 base64 编码的字符串,您能告诉我们您到目前为止所做的尝试吗?
标签: python json google-cloud-platform encode google-vision