Azure-Computer-Vision : Read API - Get JSON response using python sdk

Anonymous
2021-09-28T08:35:22.727+00:00

I have been able to extract the text data from the image of pdf file using Azure Computer Vision Read API using python SDK (azure-cognitiveservices-vision-computervision). However, the response is either the cognitiveservices.vision.computervision.models.ReadOperationResult or msrest.pipeline.ClientRawResponse as response from the get_read_result() API as specified in below link. Kindly let me know how to get JSON response using get_read_result() API.

https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/cognitiveservices/azure-cognitiveservices-vision-computervision/azure/cognitiveservices/vision/computervision/operations/_computer_vision_client_operations.py

Response :
{'additional_properties': {}, 'status': <OperationStatusCodes.succeeded: 'succeeded'>, 'created_date_time': '2021-09-28T08:49:01Z', 'last_updated_date_time': '2021-09-28T08:49:05Z', 'analyze_result': <azure.cognitiveservices.vision.computervision.models._models_py3.AnalyzeResults object at 0x0000023C502C32B0>}

I want the output as json response and not objects.

Azure Vision in Foundry Tools

Answer accepted by question author
Rohit Mungi 49,216 Reputation points Microsoft Employee Moderator
2021-09-28T13:23:03.89+00:00

@Anonymous With the SDK you can print out each object in the response i.e the ReadResult object's analyze_result class and its results. You can follow this snippet from documentation and print your results.

read_result = computervision_client.get_read_result(operation_id)  
      
# Print the detected text, line by line  
if read_result.status == OperationStatusCodes.succeeded:  
    for text_result in read_result.analyze_result.read_results:  
        for line in text_result.lines:  
            print(line.text)  
            print(line.bounding_box)  
print()  

You also have the option to use REST API with python to use the JSON response directly from the get read results API.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.