【发布时间】:2019-07-27 22:15:45
【问题描述】:
我正在尝试使用 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