let*_*ite 5 ocr image-processing computer-vision google-vision google-cloud-vision
我正在使用 Google Vision OCR 从 python 中的图像中提取文本。
使用以下代码片段。
然而,置信度分数总是表明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}')
Run Code Online (Sandbox Code Playgroud)
例如:迭代的输出
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
Run Code Online (Sandbox Code Playgroud)
小智 2
我设法重现了您的问题。我使用以下函数并获得所有项目的置信度 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))
Run Code Online (Sandbox Code Playgroud)
然而,当使用文档中的“尝试 API”选项的相同图像时,我获得了置信度非 0 的结果。从本地图像检测文本时也会发生这种情况。
人们应该期望使用这两种方法时置信度具有相同的值。我已经打开了问题跟踪器,请在此处查看。
| 归档时间: |
|
| 查看次数: |
3910 次 |
| 最近记录: |