从计算机visio调用ocr api时,我没有得到预期的结果

问题描述 投票:1回答:2

我正在尝试使用计算机visio中的ocr方法从特定图像中提取所有文本。然而,它不会返回我知道的信息,因为当我在此页面https://azure.microsoft.com/es-es/services/cognitive-services/computer-vision/的可用选项中直接分析图像时,它确实返回数据。

这是我试图从qazxsw poi获取数据的图像

我已经关注了azure文档站点中提供的所有python教程。

https://bitbucket.org/miguel_acevedo_ve/python-stream/raw/086279ad6885a490e521785ba288914ed98cfd1d/test.jpg

这是我目前的输出:

import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from PIL import Image
from io import BytesIO

subscription_key = "<Subscription Key>"

assert subscription_key

vision_base_url = "https://westcentralus.api.cognitive.microsoft.com/vision/v2.0/"

ocr_url = vision_base_url + "ocr"

image_url = "https://bitbucket.org/miguel_acevedo_ve/python-stream/raw/086279ad6885a490e521785ba288914ed98cfd1d/test.jpg"

'''image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/" + \
    "Atomist_quote_from_Democritus.png/338px-Atomist_quote_from_Democritus.png"
'''

headers = {'Ocp-Apim-Subscription-Key': subscription_key}
params  = {'mode' : 'Printed'}
data    = {'url': image_url}
response = requests.post(ocr_url, headers=headers, params=params, json=data)
response.raise_for_status()

analysis = response.json()
print(analysis)

更新:解决方案是使用recognText而不是计算机visio的ocr函数。

python azure ocr vision
2个回答
0
投票

我看到你的代码中有两个图像。

评论栏中的一个如下所示。这是一个很好的样本,类似于着名的手写数据集{u'regions': [], u'textAngle': 0.0, u'orientation': u'NotDetected', u'language': u'unk'} 。这个类数据集的特点是没有任何强噪声像素。

MNIST

然而,下面的另一个,整个图像都有强烈的噪声像素,即使我认为超过99%。

enter image description here

所以他们是两个场景。 Azure Cognitive Service的OCR性能取决于训练模型中的样本数据集。因此,实际上计算机视觉中的OCR可以用训练样本检测这些相似的图像。

第二个图像的正确方法是首先检测足够小的像素区域包括文本内容,然后将其剪切以进行ocr调用。例如,如果ocr是来自汽车头部图像的许可证编号,则仅需要车牌的图像部分。


0
投票

解决方案是使用recognText方法而不是计算机视觉中的ocr方法。

首先,您需要发送一个帖子,然后使用operationid发出get请求以获取de结果。

enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.