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

Keerthana B.S 21 Reputation points
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 Computer Vision
Azure Computer Vision
An Azure artificial intelligence service that analyzes content in images and video.
305 questions
{count} votes

Accepted answer
  1. romungi-MSFT 41,861 Reputation points Microsoft Employee
    2021-09-28T13:23:03.89+00:00

    @Keerthana B.S 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.


0 additional answers

Sort by: Most helpful