【问题标题】:Is it possible to give text format hints in google vision api?是否可以在 google vision api 中给出文本格式提示?
【发布时间】:2018-04-05 14:55:49
【问题描述】:

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

在云视觉api中,有没有办法给出关于类型的提示?

示例:出现的唯一文本是 dd/mm/yy,d,m 和 y 是数字

我发现的唯一内容是文档中的语言提示。

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

【问题讨论】:

    标签: ocr google-cloud-vision icr


    【解决方案1】:

    无法提供有关类型的提示,但您可以使用 client libraries 过滤输出。我从here 下载了detect.pyrequirements.txt 并修改了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(“letter”,”number”) 应该可以解决错误的识别。我为这个例子添加了最常见的情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多