我正在尝试使用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
答案 0 :(得分:0)
在ImageAnnotatorClient.DetectDocumentText(您的图像)之后,您可以遍历每个块内的块和单词,并尝试在每个单词上匹配正则表达式以查找日期和数字。