google视觉api中是否可以给出文本格式提示?

Is it possible to give text format hints in google vision api?

我正在尝试检测图像中孤立的手写日期。

在云视觉api中,有没有办法提示类型?

示例:唯一存在的文本将是 dd/mm/yy,d、m 和 y 是数字

我唯一找到的是文档中的语言提示。

有时我得到的结果包含 O 之类的字母,而不是 0

无法提供有关类型的提示,但您可以使用 client libraries. I downloaded detect.py and requirements.txt from here 过滤输出并修改 detect.py(在 def detect_text,第 283 行之后):

    response = client.text_detection(image=image)
    texts = response.text_annotations

    #Import regular expressions
    import re

    print('Date:')

    dateStr=texts[0].description
    # Test case for letters replacement
    #dateStr="Z3 OZ/l7"
    #print(dateStr)

    dateStr=dateStr.replace("O","0")    
    dateStr=dateStr.replace("Z","2")    
    dateStr=dateStr.replace("l","1")    

    dateList=re.split(' |;|,|/|\n',dateStr)

    dd=dateList[0]
    mm=dateList[1]
    yy=dateList[2]
    date=dd+'/'+mm+'/'+yy 
    print(date)
    #for text in texts:
        #print('\n"{}"'.format(text.description))
    #print('Hello you!')
        #vertices = (['({},{})'.format(vertex.x, vertex.y)
        #            for vertex in text.bounding_poly.vertices])

        #print('bounds: {}'.format(','.join(vertices)))
    # [END migration_text_detection]
# [END def_detect_text]

然后我使用以下命令行在虚拟环境中启动 detect.py

python detect_dates.py text qAkiq.png

我得到了这个:

23/02/17

很少有字母会被误认为数字,所以使用str.replace(“字母”,”数字”)应该可以解决误识别问题。我为这个例子添加了最常见的情况。