如何在本地图像上应用带有请求库的Azure OCR API



实际上,我正在使用ocr.space作为ocr API,用于我的项目中的ocr任务(这是一个python项目(。

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

我遵循了这份文档https://learn.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts-sdk/client-library?tabs=visual-工作室&pivots=编程语言python。

正如您所看到的,computervision_client.read(…(函数需要一个图像URL才能正常工作。然而,我想在我的计算机的本地映像上应用这个API。

你对伴侣有什么建议?

谢谢

我也有同样的问题,他们在github上讨论过。有人列出了一个很好的例子,可以将所有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)

最新更新