【问题标题】:OCR confidence score from Google Vision API来自 Google Vision API 的 OCR 置信度得分
【发布时间】:2020-10-22 05:56:54
【问题描述】:

我正在使用 Google Vision OCR 从 python 中的图像中提取文本。
使用以下代码 sn -p.
但是,置信度分数总是显示0.0,这绝对是不正确的。

如何从 Google 响应中提取单个字符或单词的 OCR 置信度分数?

 content = cv2.imencode('.jpg', cv2.imread(file_name))[1].tostring()
 img = types.Image(content=content)
 response1 = client.text_detection(image=img, image_context={"language_hints": ["en"]})
 response_annotations = response1.text_annotations
 for x in response1.text_annotations:
      print(x)
      print(f'confidence:{x.confidence}')

例如:迭代的输出

description: "Date:"
bounding_poly {
  vertices {
    x: 127
    y: 11
  }
  vertices {
    x: 181
    y: 10
  }
  vertices {
    x: 181
    y: 29
  }
  vertices {
    x: 127
    y: 30
  }
}

confidence:0.0

【问题讨论】:

  • 试图在演示 api 中发布图像?不同的结果?也可能删除语言提示会产生一些影响
  • 演示 api?可以进一步阐述。它完美地 OCRed,甚至每个字符的大小写都正确找到了空格数。它的信心是零,不加起来
  • 在这里试试 -> cloud.google.com/vision,同样的信心?
  • 遇到与google-cloud-vision==1.0.0相同的问题
  • @letsBeePolite 请问有关于这个问题的消息吗?

标签: image-processing computer-vision ocr google-cloud-vision google-vision


【解决方案1】:

我设法重现了您的问题。我使用了以下函数并获得了所有项目的置信度 0.0。

from google.cloud import vision

def detect_text_uri(uri):
    client = vision.ImageAnnotatorClient()
    image = vision.types.Image()
    image.source.image_uri = uri

    response = client.text_detection(image=image)
    texts = response.text_annotations
    print('Texts:')

    for text in texts:
        print('\n"{}"'.format(text.description))

        vertices = (['({},{})'.format(vertex.x, vertex.y)
                    for vertex in text.bounding_poly.vertices])

        print('bounds: {}'.format(','.join(vertices)))
        print("confidence: {}".format(text.confidence))

    if response.error.message:
        raise Exception(
            '{}\nFor more info on error messages, check: '
            'https://cloud.google.com/apis/design/errors'.format(
                response.error.message))

但是,当在documentation 中使用带有“Try the API”选项的相同图像时,我获得了置信度非 0 的结果。从本地图像中检测文本时也会发生这种情况。

人们应该期望使用这两种方法的置信度具有相同的值。我已经打开了一个问题跟踪器,请查看here

【讨论】:

【解决方案2】:

检索 GOCR 响应的正确置信度值的工作代码。

(使用document_text_detection() 代替text_detection()

def detect_document(path):
    """Detects document features in an image."""
    from google.cloud import vision
    import io
    client = vision.ImageAnnotatorClient()

    # [START vision_python_migration_document_text_detection]
    with io.open(path, 'rb') as image_file:
        content = image_file.read()

    image = vision.types.Image(content=content)

    response = client.document_text_detection(image=image)

    for page in response.full_text_annotation.pages:
        for block in page.blocks:
            print('\nBlock confidence: {}\n'.format(block.confidence))

            for paragraph in block.paragraphs:
                print('Paragraph confidence: {}'.format(
                    paragraph.confidence))

                for word in paragraph.words:
                    word_text = ''.join([
                        symbol.text for symbol in word.symbols
                    ])
                    print('Word text: {} (confidence: {})'.format(
                        word_text, word.confidence))

                    for symbol in word.symbols:
                        print('\tSymbol: {} (confidence: {})'.format(
                            symbol.text, symbol.confidence))

    if response.error.message:
        raise Exception(
            '{}\nFor more info on error messages, check: '
            'https://cloud.google.com/apis/design/errors'.format(
                response.error.message))
    # [END vision_python_migration_document_text_detection]
# [END vision_fulltext_detection]

# add your own path
path = "gocr_vision.png"
detect_document(path)

【讨论】:

  • 改变方法不是解决办法。 document_text_detection 没有 text_detection 的目标
猜你喜欢
  • 2020-08-13
  • 2023-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-29
相关资源
最近更新 更多