question

KeerthanaBS-9686 avatar image
0 Votes"
KeerthanaBS-9686 asked KeerthanaBS-9686 edited

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

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

romungi-MSFT avatar image
0 Votes"
romungi-MSFT answered KeerthanaBS-9686 edited

@KeerthanaBS-9686 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.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the quick response. Yes, I have tried both the approaches i.e, using SDK and as REST API. I was looking for a way to convert SDK output similar to JSON response of REST API but, as you have clarified, they are different and we may have to consume the output accordingly.

0 Votes 0 ·