从computer visi调用ocr api时没有得到预期的结果

2024-06-02 19:33:24 发布

您现在位置:Python中文网/ 问答频道 /正文

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

这是用来获取数据的图像 https://bitbucket.org/miguel_acevedo_ve/python-stream/raw/086279ad6885a490e521785ba288914ed98cfd1d/test.jpg

我已经学习了azure文档站点上提供的所有python教程。你知道吗

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)

这是我的电流输出:

{u'regions': [], u'textAngle': 0.0, u'orientation': u'NotDetected', u'language': u'unk'}

更新:解决方案是使用recognizeText而不是computer visio的ocr功能。你知道吗


Tags: keyfromhttpsorg图像imageimporturl
2条回答

我看到你的代码里有两个图像。你知道吗

你的评论栏里的是下面这个。这是一个很好的示例,类似于著名的手写数据集^{}。该类数据集的特点是没有强噪声像素。你知道吗

enter image description here

然而,下面的另一个,有很强的噪声像素的所有图像,甚至我认为超过99%。你知道吗

enter image description here

所以有两种情况。Azure认知服务的OCR性能取决于训练模型中的样本数据集。所以实际上,计算机视觉中的OCR只能通过训练样本来检测这些相似的图像。你知道吗

对于第二幅图像,正确的方法是先检测出包含文本内容的足够小的像素区域,然后对其进行剪切,进行ocr调用。例如,如果ocr从车头图像中提取车牌号,则只需要车牌的图像部分。你知道吗

解决方法是使用识别文本的方法,而不是计算机视觉的ocr方法。你知道吗

首先需要发送post,然后使用operationid发出get请求以获取de结果。你知道吗

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

ocr_url = vision_base_url + "recognizeText"

response = requests.post(
    ocr_url, headers=headers,params=params, data=imgByteArr)
operationLocation = response.headers['Operation-Location']
response = requests.request('GET', operationLocation, json=None, data=None, headers=headers, params=None)

相关问题 更多 >