总结问题:
我正在尝试将多个PDF处理为用Python编写的OCR程序。在本地开发过程中,PDF位于可以处理的本地目录中,但我无法在Blob存储中找到类似文件系统的路径。从技术上讲,我知道Blob中并没有这样的文件系统,但我需要在OCR程序中传递这样的路径。我们有什么办法可以做到这一点?
我尝试过的:
目前,我有下面的代码来连接到azure.py
:中的容器和Blob
import os
import glob
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, PublicAccess
# list input PDF files
def ls_files(client, path, recursive=False):
if not path == '' and not path.endswith('/'):
path += '/'
blob_list = client.list_blobs(name_starts_with=path)
files = []
for blob in blob_list:
relative_path = os.path.relpath(blob.name, path) # blob.name is the name of blobs in containers
if recursive or not '/' in relative_path:
files.append(relative_path)
files = [f for f in files if f.endswith('.pdf')] # look for PDF files
return files
# connection string to the storage account
connect_str = '<connection string>'
# same container but different folders for inputs and outputs
container_name = 'ocr'
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
client = blob_service_client.get_container_client(container_name)
input_files = ls_files(client, '', recursive=True) # This is the input PDF files
for files in input_files:
############################
# kick off OCR program here#
############################
print('Processing ...', files, 'n')
在main.py
文件中:
import azure as az
input_directory = az.input_files # input_directory was like '/Users/xyz/path/to/local/dir'
# do regular OCR processing next
执行脚本后,Python无法识别Blob存储中的文件或路径。我们有办法在这里实现目标吗?提前谢谢。
编辑1:
我看到了这个示例代码,但我担心这是用于旧版本的Python SDK,而不是V12。也一直在考虑官方回购,但无济于事。
编辑2:
好的。在这里打开了一张机票,寻求MSFT团队的帮助,一旦我了解更多信息,就会在这里更新。解决方法是1(将文件作为内存流下载,或者2(在Python中创建一个临时文件作为占位符。欢迎提出任何建议。
您可以使用Azure存储文件共享,也可以使用Azure认知服务计算机视觉API进行OCR,而不是使用Azure存储BLOBhttps://learn.microsoft.com/en-us/azure/cognitive-services/computer-vision/concept-recognizing-text