python 如何从Azure Blob存储中存储的多个图像中提取azureocr

qhhrdooz  于 2023-02-18  发布在  Python
关注(0)|答案(1)|浏览(148)

我正在使用python代码将多个图像发送到azureblobstorage,现在我需要对这些多个图像执行azure OCR,并将结果和置信度保存在Excel工作表中
我不知道什么是下一步我的意思是如何从多个图像中提取OCR我搜索了许多文档,这是由微软提供的,但我仍然没有找到答案
我正在尝试导入BlobServiceClient,但收到导入错误,例如无法从www.example.com导入BlobServiceClientazure.blob.storage

6rvt4ljy

6rvt4ljy1#

1.在这里我安装了以下打包
1.蓝色存储blob
1.蓝色-认知服务-视觉-计算机视觉
使用pip install <Package Name>

  • 现在你可以使用下面的代码打印提取的线和图像中每一条线的置信度。
// Get the following values from portal : 

blob_storage_Connection_String = ""
Cognitive_Service_key = ""
Cognitive_Service_endpoint = ""
container_name = "testcontainer"
storage_account_name = ""

blob_service_client = BlobServiceClient.from_connection_string(blob_storage_Connection_String)

computervision_client = ComputerVisionClient(Cognitive_Service_endpoint, CognitiveServicesCredentials(Cognitive_Service_key))

container_client = blob_service_client.get_container_client(container_name)

// List of Blobs
blob_list = container_client.list_blobs()

for blob  in  blob_list:
    blob_url = "https://"+storage_account_name+".blob.core.windows.net/"+container_name+"/"+blob.name
    read_response = computervision_client.read(blob_url, raw=True)
    read_operation_location = read_response.headers["Operation-Location"]
    operation_id = read_operation_location.split("/")[-1]
    while  True:
        read_result = computervision_client.get_read_result(operation_id)
        if  read_result.status not  in ['notStarted', 'running']:
            break
        time.sleep(1)
    for  textresult  in  read_result.analyze_result.read_results:
        for  line  in  textresult.lines:
            print("Text: ",line.text)
            print("Confidence: ", line.appearance.style.confidence)
  • 这里,Azure存储容器中有2个图像,因此有两组结果

输出:

  • 此外,您还可以使用xlwt模块在excel工作表中添加line.textline.appearance.style.confidence。在向excel添加数据时,请参考aishwarya.27

相关问题