如何通过Python使用googlevisionocrapi获取词数?

2024-09-28 23:43:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我想扫描一个image文档并将图像中的word绘制成图形,我还想得到word count。通过使用Google Vision API这可能吗

我在他们的文档中没有看到任何有关字数统计的信息。如果有人以前做到过,请帮助我


Tags: 文档图像imageapi信息图形countgoogle
1条回答
网友
1楼 · 发布于 2024-09-28 23:43:43

改编自codelabs中的示例:

from google.cloud import vision

def count_words(str):
    ls1 = str.split()
    return len(ls1)


image_uri = 'gs://cloud-vision-codelab/otter_crossing.jpg'

client = vision.ImageAnnotatorClient()
image = vision.types.Image()
image.source.image_uri = image_uri

response = client.text_detection(image=image)

for text in response.text_annotations:
    print(text.description)
    print(count_words(text.description))

我的建议是:也给其他OCR库一个机会

相关问题 更多 >