首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自Google Vision API的OCR置信度得分

来自Google Vision API的OCR置信度得分
EN

Stack Overflow用户
提问于 2020-07-02 01:56:10
回答 2查看 1.7K关注 0票数 5

我正在使用Google Vision OCR从python中的图像中提取文本。

使用下面的代码片段。

但是,置信度得分总是显示0.0,这肯定是不正确的。

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

代码语言:javascript
复制
 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}')

示例:迭代的输出

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2020-07-16 20:12:33

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

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2020-08-18 01:23:29

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

(使用document_text_detection()而不是text_detection())

代码语言:javascript
复制
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)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62682707

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档