我是Google Vision的新手,我想创建代码以接收异步响应。例如,创建一个JSON文件进行响应,然后再加载该JSON文件并继续使用识别器。
我正在尝试使用Google的一些代码,但是当我尝试读取JSON文件时,它无法像在同步模式下那样工作。
这是我将响应保存到JSON文件的方式:
with open(path_source_image, 'rb') as image_file:
tmp_image_opened = image_file.read()
tpm_image_opened_to_vision = vision.types.Image(content=tmp_image_opened)
tpm_vision_client = vision.ImageAnnotatorClient()
tpm_response_from_vision = tpm_vision_client.document_text_detection(image=tpm_image_opened_to_vision)
这是我尝试读取和使用JSON文件的方式:
with open('proyecto/2_MILE.json') as fp:
document = json.load(fp)
for page in document.pages:
for block in page.blocks:
for paragraph in block.paragraphs:
for word in paragraph.words:
assembled_word = assemble_word(word)
if (assembled_word == 'LEIDY'):
return word.bounding_box.vertices[0]
但是它不起作用,它说
in find_word_location for page in document.pages: AttributeError: 'dict' object has no attribute 'pages'