我正在尝试使用Google Vision API检测手写日期。您知道是否有可能强迫它检测日期(DD/mm/yyyy),或者至少只能增加可靠性的数字?
我使用的函数,以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
imageAnnotatorClient.detectDocumentText(您的图像),您可以在每个块内部的块和单词上迭代,并尝试在每个单词上匹配一个正则表达式以查找日期和数字。