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

问题描述 投票:0回答:1

我正在尝试使用Google Vision API检测手写日期。你知道是否有可能强迫它检测日期(DD / MM / YYYY),或者至少只是为了增加可靠性?

我使用的函数,将一个Image作为np.array作为输入:

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
computer-vision google-vision handwriting-recognition
1个回答
-1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.