Принудительно Google Vision API для определения дат / чисел - PullRequest
1 голос
/ 06 марта 2019

Я пытаюсь определить рукописные даты с помощью API Google Vision. Знаете ли вы, можно ли заставить его определять даты (ДД / ММ / ГГГГ) или хотя бы числа только для повышения надежности?

Функция, которую я использую, принимает изображение в качестве 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

1 Ответ

0 голосов
/ 23 марта 2019

После ImageAnnotatorClient.DetectDocumentText (ваше изображение) вы можете перебирать блоки и слова внутри каждого блока и пытаться сопоставить регулярное выражение по каждому слову, чтобы найти даты и числа.

...