首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >强制Google Vision API检测日期/数字

强制Google Vision API检测日期/数字
EN

Stack Overflow用户
提问于 2019-03-06 17:41:38
回答 1查看 464关注 0票数 1

我正在尝试使用Google Vision API来检测手写日期。您是否知道是否可以强制它检测日期(DD/MM/YYYY),或者至少是为了增加可靠性而检测数字?

我使用的函数将图像作为np.array作为输入:

代码语言:javascript
复制
def detect_handwritten_text(img):
"""Recognizes characters using the Google Cloud Vision API.
Args:
    img(np.array) = The Image on which to apply the OCR.

Returns:
    The recognized content of img as string.
"""

from google.cloud import vision_v1p3beta1 as vision
client = vision.ImageAnnotatorClient()

# Transform np.array image format into vision api readable byte format
sucess, encoded_image = cv.imencode('.png', img)
content = encoded_image.tobytes()

# Configure client to detect handwriting and load picture
image = vision.types.Image(content=content)
image_context = vision.types.ImageContext(language_hints=['en-t-i0-handwrit'])

response = client.document_text_detection(image=image, image_context=image_context)
return response.full_text_annotation.text
EN

回答 1

Stack Overflow用户

发布于 2019-03-23 16:57:21

在ImageAnnotatorClient.DetectDocumentText(您的图像)之后,您可以遍历块和每个块中的单词,并尝试在每个单词上匹配一个正则表达式以查找日期和数字。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55019870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档