python - 如何使用 Python 的 Google Vision OCR API 获取字数?
问题描述
我想扫描一个image
文档并绘制word
来自图像的图形,我还想获得word count
. 这可以通过使用Google Vision API
吗?
我没有在他们的文档中看到任何关于字数的相关信息。如果有人以前做到这一点,请帮助我。
解决方案
改编自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 库。
推荐阅读
- python - lpsolve55 中的数字精度
- python - 尝试用 Python 制作康威的生命游戏
- c# - C# Charts:删除空列并显示所有列名
- python - 获取 GPS 位置 1 公里步行距离内的节点 OSMNX
- excel - 在excel中一次堆叠5列离散列
- blockchain - Blockchain explorer api 用于从各种区块链获取交易
- multiple-columns - 有没有办法在雪花中旋转列?
- r - 在 r 中使用 qmap(分位数映射)进行 CMIP 6 缩小
- java - spring-boot ConcurrencyFailureException oracle
- caching - 是否有咖啡因功能可以在定义的时间后从缓存中清除特定项目并同时重新创建它?