python - 如何在本地镜像上应用 Azure OCR API 和 Request 库?

标签 python azure computer-vision azure-functions ocr

实际上,我在我的项目(这是一个 python 项目)中使用 ocr.space 作为 OCR API 来执行 OCR 任务。

我想使用 Azure OCR API 并检查哪个 API 比另一个更好。

我遵循了此文档 https://learn.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts-sdk/client-library?tabs=visual-studio&pivots=programming-language-python .

如您所见,computervision_client.read(...) 函数需要图像 URL 才能正常工作。但是,我想将此 API 应用于我计算机中的本地镜像。

friend 们有什么建议吗?

谢谢

最佳答案

我也遇到了同样的问题,他们在 github 上讨论了 hereAnd somebody put up a good list of examples用于将所有 Azure OCR 功能与本地镜像结合使用。尝试使用 read_in_stream() 函数,例如

with open("path_to_image.png", "rb") as image_stream:
        job = client.read_in_stream(
            image=image_stream,
            mode="Printed",
            raw=True
        )
operation_id = job.headers['Operation-Location'].split('/')[-1]
image_analysis = computervision_client.get_read_result(operation_id)
while image_analysis.status.lower() in ['notstarted', 'running']:
    time.sleep(1)
    image_analysis = computervision_client.get_read_result(
      operation_id=operation_id)

print(image_analysis)
lines = [res.lines for res in image_analysis.analyze_result.read_results]
print(lines)

关于python - 如何在本地镜像上应用 Azure OCR API 和 Request 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68070488/

相关文章:

opencv - 从凸点获取角

python - 与类相同类型的类变量

python - 如何获得 timezone.now() 之前的 1 天

python - 使用时区打印正确的时间,Python

python - 访问通过 Xlwt 库 (Python) 生成的 .dtsx 中的 Excel 文件会引发错误 CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER

java - 使用 Java 的 Azure 函数 - 如何创建 @BlobTrigger

asp.net - Telerik ASP.NET RadEditor 和 Azure Blob 存储?

node.js - 将 es2015 Nodejs 站点部署到 azure

c++ - findHomography()中得到的矩阵的单应分解

opencv - 缺少自定义级联分类器的检测频率